This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
Joined: Apr 08, 2003
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.
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.
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 ]
Joined: Nov 29, 2005
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: