• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remember the page which posted

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
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?
(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")
Thanks for the help,
Erik Pragt
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could set a cookie with the name of the page in every page of your application.
Bill
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
You could set a cookie with the name of the page in every page of your application.
Bill


Wow is that overkill... you don't need to know this from every page, just for forms (or at least that's what's implied). Further, cookies are frequently blocked by users' browser preferences.
Simply put a hidden field in your form. You could even write a custom tag if you wanted that would generate a hidden field containing the page URL based on the request properties.
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William: now this would be an overkill! I said I didn't want to add an extra parameter, so I sure don't want to add a cookie, even if my client (IE, Opera, Nokia 6310i WML browser) has cookies turned on.
David: I don't want to add the parameter, so your hidden parameter is a good idea (and maybe the only one..... ) but this is the thing I actually did NOT wanted....so if there are any other solutions: please let me know!
Thanks, Erik
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be this message in the Servlet forum will help:
https://coderanch.com/t/281924/JSP/java/servlet-know-caller
Thanks, Sudd
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Erik Pragt:
David: I don't want to add the parameter, so your hidden parameter is a good idea (and maybe the only one..... ) but this is the thing I actually did NOT wanted....so if there are any other solutions: please let me know!


Sorry, somehow skipped reading that in the original message... anyway, if you eliminate using request properties, and eliminate using request parameters, that leaves only request attributes or session attributes. Request attributes can't be set until you have a request, i.e. the form is submitted, so that's not an option. That leaves session attributes, which you can set when the form is displayed.
However, this opens the risk of mixing form data and form pages if the user does this:
1) Fill/Submit form 1
2) Fill/Submit form 2
3) hits back a few times to form 1's result page
4) hits refresh and opts to resubmit the form data
Besides which, this is not a good use of session data.
So unfortunately, you probably want to choose one of the options you wanted to avoid--using request headers or form parameters...
--David
 
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
thanks all for the help! I will 'study' (don't know a better word at this time) your answers, and determine which one to take.
Thanks again,

Erik Pragt
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic