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>