Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Baaziz Hamza
Greenhorn
Posts: 8
Google Web Toolkit Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to create a bad design?
 
Baaziz Hamza
Greenhorn
Posts: 8
Google Web Toolkit Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic