File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the typical servlet/jsp handoff?

 
Tom Joiner
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Benjamin Weaver
Ranch Hand
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Benjamin Weaver:
You might want to learn something about JSTL.


 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic