• 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

How can I tell which Servlet call JSP

 
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
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
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic