• 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

who call the servlet?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I want to use MVC pattern in my app. I use a Servlet as a handler with many jsps, but how the servlet knows which jsp is calling it?
I think one solution is using a hidden field which contains the path of the jsp and pass it to servlet.
Is there any other solution?
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try getRequestURI()? It returns the part of the URL that comes after the host and port, but before any parameters. Hidden form fields will also work though.
 
Amir Kamran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for early reply!
The method getRequestURI() and also the method getRequestURL() will return the information of current page not of that from which the page is called.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One technique I use is to put the name of the current page in the session. For example, if the user is at the "Main Menu" page, getting the attribute "currentPage" from the Session will return that string. Then, before I forward to another JSP page, I can simply set that session variable to the name of the page that I'll be forwarding to. This way, I always know where to look to determine where the user is and I don't have to include hidden fields in all of my pages that don't really mean anything. After all, does your JSP really care what the servlet calls it?
I also find that it's usually good practice to store my screen names as constants in some class (possibly the servlet, but I usually make another class to put them in to keep it from getting cluttered) or in a propeties file.
I hope that helps,
Corey
 
Amir Kamran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again!
Thanks Cory its a good solution, but i have another one the URI of request sender can be retrieve through a header name Referer.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about storing the url in a cookie?
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the header Http Referer
 
reply
    Bookmark Topic Watch Topic
  • New Topic