aspose file tools*
The moose likes Servlets and the fly likes What is the typical servlet/jsp handoff? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What is the typical servlet/jsp handoff?" Watch "What is the typical servlet/jsp handoff?" New topic
Author

What is the typical servlet/jsp handoff?

Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
I want to know the typical way that a servlet creates dynamic data to hand off to the jsp page. Here is a tutorial:

http://wdvl.internet.com/Authoring/Java/Servlets/sample.html

That demonstrates handing off data by using a session object



And then the jsp page extracts this with:



Is this the typical paradigm for handing data, through the session? How about large lists of information? How is that typically handled?

Thanks for any ideas.
[ October 20, 2006: Message edited by: Tom Joiner ]

SCJP
Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
Others will have more precise and informed answers, but I asked the same question once: here are 3 ways you can hand off data: (1) put it into the HttpSession object, as you have done; (2) put into the HttpServletResponse, using a very similar put call, as I remember; (3) insert it into either a Session or Response object a Java Bean (possibly of your own design) which bundles this and your other parameters together. You load the bean with your parameters, then load the entire Bean instance as outlined above.

Hint: learn about the different kinds of Application Scope (Page, Request, Session, Application (I think), which determine the life of your parameters after you have handed them off.
Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
Woops, forgot the Jsp end. All of the methods I outlined can be followed by jsp code that extracts parameters in much the same way you have done. JSTL (Java Server Tag Library) makes it even easier to access Session, Request, and bean objects. You might want to learn something about JSTL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Session scope should only be used when the scoped variable needs to exist beyond the current request/response cycle.

For the 99.99% of the time that data is just being passed to the JSP for display, request scope should be used.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Originally posted by Benjamin Weaver:
You might want to learn something about JSTL.


Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I do not fully agree with this.While deciding the scope , we should make sure that the object exists for least amount of time.In your case I would certainly go for request scope , not session.In session we need to store those objects which are required through out the use session , like the user preference.

One more thing which I have read in many of the forums , that keep less amount of data in session.As long as your application is not clustered , its fine.Actually only the session id is the one that travels from the client to the server , not the objects that are contained in the session.
But in case of clustered envirinment , the session object might need to be passivated and pushed to some other node in the cluster , in that case keeping the session light weight is useful.


Rahul Bhattacharjee
LinkedIn - Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Originally posted by Rahul Bhattacharjee:
I do not fully agree with this.While deciding the scope , we should make sure that the object exists for least amount of time.In your case I would certainly go for request scope , not session.


So where's the disagreement? That's exactly what I said.
[ October 21, 2006: Message edited by: Bear Bibeault ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I do not agree with


I want to know the typical way that a servlet creates dynamic data to hand off to the jsp page. Here is a tutorial:

http://wdvl.internet.com/Authoring/Java/Servlets/sample.html

That demonstrates handing off data by using a session object


code:
--------------------------------------------------------------------------------

HttpSession userSession = req.getSession(true);userSession.putValue("userName", uName);

--------------------------------------------------------------------------------



And then the jsp page extracts this with:


code:
--------------------------------------------------------------------------------

<%= session.getValue("userName")%>

--------------------------------------------------------------------------------



Is this the typical paradigm for handing data, through the session? How about large lists of information? How is that typically handled?



Sorry for the confusion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the typical servlet/jsp handoff?