|
Sponsored Links
Resources
Enterprise Java Research Library
Get Java white papers, product information, case studies and webcasts
|
Web tier: servlets, JSP, Web frameworks
Web tier: servlets, JSP, Web frameworks
Web tier: servlets, JSP, Web frameworks
|
Messages: 5
Messages: 5
Messages: 5
Printer friendly
Printer friendly
Printer friendly
Post reply
Post reply
Post reply
XML
XML
XML
|
 |
request.setAttribute versus session.setAttribute
I want to confirm the differences between request.setAttribute(key, value) versus session.setAttribute(key, value).
My understanding is that request.setAttribute only make the key available in the following jsp page. But session.setAttribute will make the key available in many pages, as long as in the same session, and browser not close.
For example, the flow like page1->page2->page3->page4. session.setAttribute will make the key available in all pages. But if we use request.setAttribute in page2, then only page3 can get the key value set in page2.
Please advise if i miss something. thanks!!
|
|
Message #144013
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
request.setAttribute versus session.setAttribute
hi Matt,
Your understanding of the difference between request.setAttribute and session.setAttribute is perfect....
But just to add to that request.setAttribute(): >>>>>May help you in getting rid of the hidden fields. >>>>>Use it most of times when you just need the attribute just for the consecutive page.
session.setAttribute(): >>>>>May help you in keeping the information through out the session e.g. db connections >>>>>but be clear where to use it.
Best of Luck.....
|
|
Message #144500
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
request.setAttribute versus session.setAttribute
>>My understanding is that request.setAttribute only make the >>key available in the following jsp page.
You should also consider how you move from page to page, if you use forward, then you are passing the request and could pass the request along to as many pages as you like. The key will be available as long as the request it was set in is the current request.
|
|
Message #144681
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
request.setAttribute versus session.setAttribute
Is it very simple to understand.
If you know about the "page scope", you know the "request scope".
request's attirbute is only availible in the "request" object lifetime. filter, servlet, jsp, include, forward are using same request object.
page's attirbute is only availible in the "page" object lifetime. You can't use page's attribute in filter, because there is no page loaded yet. you can use them in the jsp file/servlet, but if you do a forward/include, the attribute in "page" will not pass to them.
>request.setAttribute make the key available in the following jsp page
NO, unless your "following jsp page" is meaning forward the page by <jsp:forward>
|
|
Message #146612
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
request.setAttribute versus session.setAttribute
HttpRequest object is created and maintained for each request/response call. Onse response is sent to the client, request object is destroyed. Forwarding from one page to another is done on the server, so the request is preserved. Redirecting is done using roundrip through browser, so old request is destroyed and a new one is created.
|
|
Message #214676
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
using request.setAttribute instead of Hidden fields
Dear Amit, Is it possible to use request.setAttribute on a JSP page and then on HTML Submit get the same request attribute in the Servlet? I am just curious how we can do away with the hidden fields, if all we want is to just pass the contents of a huge List containing different objects, without using session.
regards Vijay
|
|
 |
Hot threads
Hot threads
Hot threads
|
More hot threads
More hot threads
More hot threads
|
 |
Brian Goetz continues to lift the lid and peak into the inner workings of Java in Java Urban Performance Legends. In this article he exposes the fallacy behind some of the more common performance myths found in the annals of the JVM.
(92 comments,
last posted
March 14, 2008)
Bruce Tate, author of Better, Faster Lighter Java and Bitter EJB has come out with a new book called Beyond Java. Bruce has an epiphany about the future of software development. Does it include Java?
(770 comments,
last posted
September 23, 2009)
Looks like today AJAX concept have several interpretations. We can distinguish different approaches of AJAX integration. Can they co-exist within the same application? Can we talk about layered AJAX integration?
(68 comments,
last posted
May 08, 2008)
Artima has published a short article describing the Design-Time API for JavaBeans, which was recently approved as JSR 273. This API promises to bring VB-like ease to Java development, but may face a cultural bias among Java developers who tend to think more in terms of class libraries than components.
(226 comments,
last posted
February 01, 2010)
There is plenty of speculation today regarding a potential buyout of Sun Microsystems by Scott McNealy and Silver Lake Partners. How would privatization of Sun affect Java?
(16 comments,
last posted
May 15, 2009)
More hot threads »
|
|