• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing request object...

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic