Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about HttpServletRequest.setAttribute()  RSS feed

 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a question.If I set an attribute using HttpServletRequest.setAttribute() in a jsp page and then forward the request to a servlet which in turn forwards the request to another jsp page after performing some calculations, will the attribute still be available to the 2nd jsp page?
Subbu
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It deppends on your session scope settings.
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I thought the scope settings applied to Beans alone and not to sessions.
Subbu
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

when you set an attribute and then you want to recover it you do:
session.getAttribute(String nameOfAttribute);
so you have to create a session objetc(i.e- HttpSession session = request.getSession(true);
)

 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry youre write, Im used to write Servlets...
The <jsp:useBean name... scope=...> it�s about beans , the session I mean is this one I�ve post before and in jsp its an implicit variable like request or response.
 
Anuj Anand
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how did u finally code it
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setAttribute() is an HttpSession method not HttpServletRequest method.
Do you want an example Anuj Anand?
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marcos Maia:
setAttribute() is an HttpSession method not HttpServletRequest method.
Do you want an example Anuj Anand?

Hi,
In Servlet 2.2 setAttribute() is a method available in HttpServletRequest also.You can refer to
http://java.sun.com/products/servlet/2.2/javadoc/index.html
for further information.
Subbu
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Txs for the information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!