URL87
URL87

Reputation: 11012

Reveal / know / get the sending page using request or session in servlet

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

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

And the required doPost in 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 the page (in this case - source.jsp) sending the request to this servlet? Is there a method in request/session?

Upvotes: 5

Views: 1691

Answers (2)

kapandron
kapandron

Reputation: 3671

Use passing parameter in a request through a hidden field:

In your jsp page:

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

In your servlet:

String namePage = request.getParameter("namePage");

Upvotes: 4

rickz
rickz

Reputation: 4474

String referer = request.getHeader("referer"); 

But read Alternative to "Referer" Header
(especially BalusC's answer).

Upvotes: 3

Related Questions