672329 members! Sign up to stay informed.

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

Posted by: Matt Louden on October 26, 2004 DIGG
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!!

Threaded replies

·  request.setAttribute versus session.setAttribute by Matt Louden on Tue Oct 26 20:55:19 EDT 2004
  ·  request.setAttribute versus session.setAttribute by Amit Sharma on Wed Oct 27 01:21:04 EDT 2004
    ·  using request.setAttribute instead of Hidden fields by Vijay Deshmukh on Wed Aug 02 10:11:27 EDT 2006
  ·  request.setAttribute versus session.setAttribute by Nathan Comstock on Sun Oct 31 23:33:01 EST 2004
  ·  request.setAttribute versus session.setAttribute by Dennis Cheung on Tue Nov 02 01:16:19 EST 2004
  ·  request.setAttribute versus session.setAttribute by Michael Jouravlev on Thu Nov 18 17:06:03 EST 2004
  Message #144013 Post reply Post reply Post reply Go to top Go to top Go to top

request.setAttribute versus session.setAttribute

Posted by: Amit Sharma on October 27, 2004 in response to Message #143994
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

Posted by: Nathan Comstock on October 31, 2004 in response to Message #143994
>>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

Posted by: Dennis Cheung on November 02, 2004 in response to Message #143994
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

Posted by: Michael Jouravlev on November 18, 2004 in response to Message #143994
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

Posted by: Vijay Deshmukh on August 02, 2006 in response to Message #144013
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

Recent active threads Recent active threads Recent active threads More More More
Oracle's Bold Plans for Java Bode Well
Sobel edge detection using Java Advanced Imaging
Using Restriction base in WSDL
BugTracker with Twitter Connector and Ajax Workflow Editor
Language-oriented Programming and Language Workbenches
More active threads »
Top posters of the weekTop posters of the weekTop posters of the week
This list contains the members who have made the most posts in all forums over the last 7 days:
  1. Reza Rahman
  2. James Watson
  3. brad mcevoy
  4. Alex Besogonov
  5. Peter Monks
Hot threads Hot threads Hot threads More hot threads More hot threads More hot threads

Object pooling is now a serious performance loss

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)

Beyond Java

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)

Three forms of AJAX: solid, liquid and gas.

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)

Design-Time API Promises to make Java more like VB

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)

Will Sun be that target of a management buyout?

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 »

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy      Powered by JIVE
Site Map