aspose file tools*
The moose likes JSP and the fly likes How can I tell which Servlet call JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How can I tell which Servlet call JSP" Watch "How can I tell which Servlet call JSP" New topic
Author

How can I tell which Servlet call JSP

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jun 06, 2011
Posts: 60

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

Joined: Jan 10, 2002
Posts: 61232
    
  66

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I tell which Servlet call JSP