• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I tell which Servlet call JSP

 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two diffrent Servlets that call the same JSP. Depending on which Servlet called the JSP I want to do diffrent logic for each but the JSP is 95% the same. Is there a way to find out which Servlet called it, or is it better just to keep it simple and pass a diffrent parm from each Servlet and intergate it ? Simple Question but I want to use best practice, Thanks
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's better for the servlets to set things up so that the JSPs can just output data. That's a general rule and not just an answer to this specific question.

I don't know what you mean by "pass a different parm" but then I also don't know what you mean when you say the servlets "call" a JSP. If the servlets are forwarding to the JSP then they should just set some request attributes which the JSP will look at. If you meant something else it would help if you clarified that using standard terminology.
 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, Thanks you answered my question. I will set the request attributes and intergate those. I have a MainFrame background so Parms and Calls are still in my head. I should have said set attributes and forward to JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, the proper term is "scoped variable".

For others that may come across this topic:

Think of it like a Java method. If someone were to ask "My method needs to to do something a little different when called from different locations. How can I find out with method called me so I can switch on that?", I'm sure every one would immediately say "Are you nuts? Just pass a parameter that you use to make your decision!"

Same deal!

Also think in terms of the strong versus weak coupling. Which approach is more versatile? Less fragile? More easily understood?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic