The following code example demonstrates how to Redirect Another Page Using JSP.

In this code, the sendRedirect method of the response object is used to redirect to the specified URL. The URL can be a relative or an absolute path, depending on your needs.

Note that the sendRedirect method sends a 302 Found HTTP response to the client, which causes the client to make a new request to the specified URL.

In order to redirect to another page using JSP, you can use the following code.

<% response.sendRedirect("http://www.example.com/newPage.jsp"); %>

The following code shows the complete application in JSP that redirects to another page.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Redirect Example</title>
</head>
<body>
  <%
    response.sendRedirect("http://www.example.com/newPage.jsp");
  %>
</body>
</html>

As can be seen in the above code, we use the sendRedirect() method to redirect to another page in JSP.


Further Reading

Understanding Enterprise Java Beans

Java Practice Exercise

Princites