If the only thing that your servlet does is process the form data irrespective of the source
JSP page and does not maintain any state information like a controller/dispatcher does, then you may want to convert it into a Filter and let it intercept the requests to all such JSP pages. Follow these steps:
1. Convert the Servlet (MyServlet) into a Filter (say, MyFilter).
2. Instead of posting to MyServlet, let the JSP page post to itself. <form action='/set_contents.jsp'>
3. In web.xml, map the URL /set_contents.jsp to MyFilter.
Originally posted by Erik Pragt:Is it possible in a servlet to see from which page the post was done, without using the http header 'referer' or using an attribute in the page. For example, when I have a page (set_contents.jsp) which posts to a servlet (MyServlet), is it possible to see in the MyServlet to see that the post came from set_contents.jsp?
Since each JSP page will use its own URI, the filter can distinguish between the different pages using getRequestURI() if it needs to. No need to use a separate paramter.
Originally posted by Erik Pragt:(the idea is to process the contents, and than to return to the original page without using a parameter such as 'origional page="set_contents.jsp")
Add as many JSP pages as you want; just map them all to the same filter. You can use the wild character * too in the <url-mapping>. The FilterChain will take care of where to forward the request after the filter processes the contents.
If your servlet cannot be converted into a filter for any reason, then you will most probably have to use one of the methods described by Bill and David.
Hope that helps
-j