Redirect pages in JSP?

I have to design several pages in jsp. After clicking on the submit button on the first page, the page should be automatically redirected to the second page.

Can you help with a quick example or a link to a tutorial that demonstrates how to implement this?


Solution 1:

<%
    String redirectURL = "http://whatever.com/myJSPFile.jsp";
    response.sendRedirect(redirectURL);
%>

Solution 2:

This answer also contains a standard solution using only the jstl redirect tag:

<c:redirect url="/home.html"/>

Solution 3:

Just define the target page in the action attribute of the <form> containing the submit button.

So, in page1.jsp:

<form action="page2.jsp">
    <input type="submit">
</form>

Unrelated to the problem, a JSP is not the best place to do business stuff, if you need to do any. Consider learning servlets.