Figure out / find out / get the submit page using a request or session in servlets

I have a jsp page (say, source.jsp) with the form:

<html>
<head>
<body>
    <form action="Servlet123" method="POST">
        // form fileds ... 
    </form>
</body>
</head>
</html>

And required doPostin the servlet -

@WebServlet("/Servlet123")
public class Servlet123 extends HttpServlet {
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

          //use with requset...
    }
}

How can I get a page (in this case - source.jsp) by sending a request to this servlet? Is there a method in the request / session?

+5
source share
2 answers

Use the transfer parameter in the request through a hidden field:

On the jsp page:

<form action="Servlet123" method="post">        
   <input type="hidden" name="namePage" value="sourcePage" />
</form>

In your servlet:

String namePage = request.getParameter("namePage");
+4
source
String referer = request.getHeader("referer"); 

But read the Alternate β€œReferer” Header
(especially BalusC's answer).

+3
source

All Articles