Reputation: 11012
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
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
Reputation: 4474
String referer = request.getHeader("referer");
But read Alternative to "Referer" Header
(especially BalusC's answer).
Upvotes: 3