• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing request object...  RSS feed

 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am accessing a variable abc via the request object and manipulate the bean for my operation. Now, in an attempt to create a printer-friendly page, I thought I could simply open a link from the first jsp and the request object will carry the vatiable abc with it. Guess NOT.
I am getting a NullPointerException. How else can I achieve this?

Thanks much.
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Med,
if the new page is requested the servlet engine creates a new request object for it. You need to place your information in the session object.
request.getSession().setAttribute(parameter,value);
Then you can access it from all your following pages (request).
Regards
Torsten
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't request.setAttribute("","")will serve the purpose rather than keeping it in session object??
Originally posted by Torsten Schippel:
Hi Med,
if the new page is requested the servlet engine creates a new request object for it. You need to place your information in the session object.
request.getSession().setAttribute(parameter,value);
Then you can access it from all your following pages (request).
Regards
Torsten
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vikasids sharma:
Won't request.setAttribute("","")will serve the purpose rather than keeping it in session object??

The request object is available for a request only and not across requests for which we have session object.
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per requirement mentioned ...
request object should be used rather than session object
Originally posted by Pradeep Bhat:

The request object is available for a request only and not across requests for which we have session object.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vikasids sharma:
As per requirement mentioned ...
request object should be used rather than session object

Can you explain it again for me.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that there are 2 requests
1. JSP (say first) is displayed. Before the page is displayed a variable "abc" is set in the request object.
2.printer friendly jsp is to be displayed

Am I right?
 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just when I thought I understood the differences between the Request and the Session objects, I feel a little confused. The reason I'm staying away from attaching objects to session is that I don't want objects to be hanging around if not needed, before users log out.
So how's ServletContext different from all this then?
This article show how to share objects using ServletContext.
[ September 26, 2003: Message edited by: Med Shabe ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always remove the unwanted objects from the session by calling sessio.removeAttribute method.
ServetContext can be shared by all the servlets and jsp in a application whereas a session can be used a single client only .
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how's ServletContext different from all this then?

This is a really important concept to understand in web apps. There are a number of scopes available:
page - available only within the current JSP page
request - available during a single request processing
session - available to all JSPs/servlets in same session
application (aka servlet context) - available across all JSPs/servlets in the same web application
hth,
bear
[ September 26, 2003: Message edited by: Bear Bibeault ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!