• 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

JavaBean losing reference when passed to JSP - help!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a web application using Servlets, JavaBeans and JSPs. I have a
problem when using a Servlet to create a JavaBean and then place the JavaBean into the
session object (using HttpSession.putValue), and then using
RequestDispatcher to forward control to a JSP. The JSP then uses "useBean"
to get a reference to the bean I just placed in the session. Fine. The only
problem is that somewhere, somehow when the JSP uses the bean other objects
which that bean has internal references to are lost, i.e. the variables
point to null. If I do everything from within the servlet, its fine.
Presumably the reference is ceasing to point to the object - but why.
I'm running JRun 3 and IIS.
The servlet code looks like this:
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/ContactForm.jsp");
IndividualOperation conOp = new IndividualOperation();
session.putValue("op", conOp);
dispatcher.forward(request,response);
The JSP code like this:
<jsp:useBean id="op" class="com.occam.contacts.IndividualOperation" />
<%= op.generateHTML()%>
And the bean code like this:
String strHTML = this.con.getAddressLine1();
return strHTML;
where con is a private variable within the bean which is a reference to
another object. I hope the code is of use I wasn't sure whether to include
it or not.
Please help, I'm absolutely desperate!
Thanks
Steven

[This message has been edited by Steven Briggs (edited July 20, 2001).]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U have to use scope attribute in usebean.
<jsp:useBean id="op" class="com.occam.contacts.IndividualOperation" scope="session"/>
The bean should contain all the data before u put into session.
[This message has been edited by nagesh vutukuru (edited July 20, 2001).]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,
try these changes to your code
instead of
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/ContactForm.jsp");
use :
RequestDispatcher dispatcher =
request.getRequestDispatcher("/ContactForm.jsp");
instead of :
session.putValue("op", conOp);
try :
session.setAttribute("op", conOp);
session.putValue() has been deprecated due to security reasons.u can retrieve the object using:
session.getAttribute("op");
hope this helps.

Subbu
[This message has been edited by Subbu Aswathanarayan (edited July 20, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic