• 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

Is there a way to know from which servlet a request has been redirected or dispatched ?

 
Greenhorn
Posts: 8
Google Web Toolkit Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there !
As i said in the title, if I have a controller servlet that accepts requests and redirections from multiple servlets (or any resource in general).
Is there any ways I could determine which jsp send that request or which servlet did that redirection/dispatching, without sending an extra param (origin="ServletName" for example) with every request ?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a red flag for a bad design.



Why do you need to know this? This creates strong coupling between the components, which can make your design fragile and easily broken.

If you need to make a decision based upon this info, rather than trying to find out where things came from, define a parameter that can be used to pass info that can be used to make the decision.
 
Baaziz Hamza
Greenhorn
Posts: 8
Google Web Toolkit Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:That's a red flag for a bad design.



Why do you need to know this? This creates strong coupling between the components, which can make your design fragile and easily broken.

If you need to make a decision based upon this info, rather than trying to find out where things came from, define a parameter that can be used to pass info that can be used to make the decision.



Thanks for the quick reply , I already know this solution, I'm just asking if there's a method or something in Servlet API, that does this automatically ?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you want to create a bad design?
 
Baaziz Hamza
Greenhorn
Posts: 8
Google Web Toolkit Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:So you want to create a bad design?


No ! I guess sending an extra param holding the name of the servlet with every request, and making hidden inputs in the jsp forms will do it, i was just afraid this solution was somehow dumb and heavy
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Baaziz Hamza wrote:

Bear Bibeault wrote:So you want to create a bad design?


No ! I guess sending an extra param holding the name of the servlet with every request, and making hidden inputs in the jsp forms will do it, i was just afraid this solution was somehow dumb and heavy


You're instinct there is right -- sending the name of the Servlet is not a good approach.

Step back. Take a deep breath.

What is it that you really need to know? It's not the name of the sending the servlet. Abstract what you're trying to do in your mind and figure out what it is you really need to know. Where you "came from" is never going to be the right answer.
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Baaziz Hamza wrote: making hidden inputs in the jsp forms will do it



Note, having importent values be hidden form fields from the jsp/html form is bad as well.

The first rule of security is to never trust the user's browser. You think it may be IE or Firefox or Chrome, but it could be a rogue program that is pretending to be a browser but is really trying to crack into your system.

Put the data into the session, and do not send it to and from the browser.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Baaziz Hamza wrote:

Bear Bibeault wrote:So you want to create a bad design?


No ! I guess sending an extra param holding the name of the servlet with every request, and making hidden inputs in the jsp forms will do it, i was just afraid this solution was somehow dumb and heavy


You're instinct there is right -- sending the name of the Servlet is not a good approach.

Step back. Take a deep breath.

What is it that you really need to know? It's not the name of the sending the servlet. Abstract what you're trying to do in your mind and figure out what it is you really need to know. Where you "came from" is never going to be the right answer.



One example is:
If called from form A i need to restrict the search on database to only include the current users records, if I am calling from form B i need to search for every user.

create a parameter called restrictSearchToCurrentUser (i like snappy variable names).

which means that if later on form B gets a check box saying "restrict to current user" it is a simple matter of passing the correct boolean to the method.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic