0

Friends recently i was writing code on jsp where i have to use a button to call a class and use its method.However when i tried same i received unexpected output.I tried search the reason and came across various related questions but i am still struck as i don want use EL or jstl.so basically when i am calling a javascript function on button click it is working but as soon as i put some java code lets say response.sendRedirect("/abc.jsp") the page is getting redirected even before i click button.Please help as i am really struck and not able to get solution.Below is working fine.But when I add any Java code.It is performed without click event.

</head>
<body>
    <button id="doUnzip" type="submit" name="unzip">Unzip</button>

   <script>   
  document.getElementById('doUnzip').onclick=function (){
      alert("welocome");
  };

    </script>

</body>

Now the below is not working

<body>
    <button id="doUnzip" type="submit" name="unzip">Unzip</button>
  <script>   
     document.getElementById('doUnzip').onclick=function (){
      <%
       response.sendRedirect("/index.jsp");
      %>
   };
   </script>
</body>
Lakshmi
  • 5
  • 4
  • 1
    https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – Teemu Aug 18 '17 at 07:33
  • thanks@Teemu all i can understand from the link is "All PHP code is executed on the server before the client even starts executing any of the JavaScript. There's no PHP code left in the response that JavaScript could interact with." but i am really sorry i am not able to apply it here. – Lakshmi Aug 18 '17 at 07:52
  • well now i am aware of the problem but still i need a solution.Actually i have a jsp page which has zipped images into a folder(using servlet at backend)and i want to provide a button on same page on click i want user to unzip that folder.now since source path and destination is available on jsp if i use button in the form then i am not able to get request.setAttribute and if i use request dispatcher so you now the page is getting redirected directly @Teemu – Lakshmi Aug 18 '17 at 09:42

0 Answers0