Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect from jsp using scriplet code

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>
like image 926
sampath Avatar asked Jul 01 '26 09:07

sampath


1 Answers

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;
}
like image 173
Thambi Avatar answered Jul 03 '26 23:07

Thambi