My application has a JSP, which uses scriplet code to redirect to a page based on some condition.
But what is happening is that, after the redirect code response.redirect(..), the below code is executing. I don't want to execute below code or load the JSP page, I just want to redirect immediately. See the below example and please let me know the solution.
<html>
<body>
<%
boolean condition = true;
if(condition)
response.sendRedirect("http://www.google.co.in");
System.out.println("I don't want to execute this code, I just want to redirect after above line");
%>
</body>
</html>
Return statement can be used as soon as the sendRedirect is done. In this case the code present below that will not be executed.
if(condition){
response.sendRedirect("http://www.google.co.in");
return;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With