Hello Gary,

If you want to create an instance of a bean within a servlet, and then use
the request object to forward it to a jsp page, you have to extract it from
the request object within the jsp page, like this:

<%@ page session="true"% import="BeanClass">
<%
BeanClass the_bean = (BeanClass)request.getAttribute(beanName);
%>

Hope this helps,
Andre V
World Adventures

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
[EMAIL PROTECTED]
Sent: Thursday, February 10, 2000 2:37 PM
To: Orion-Interest
Subject: Accessing a 'bean' from both servlet and jsp






Gary Albers@TIMEWEB
02/10/2000 03:36 PM

Hi Folks,

Is there any special 'trick' to being able to access an object (bean) from
within a
servlet and a jsp page?  I am not getting the same instance of the bean
when I
try to access a bean from the servlert and then a jsp page.

I do the following:
 - create a bean in a servlet,
 - get the session from the request object
 - put the bean in the session using: session.setAttribute("beanName",
bean)
 - forward to a jsp page using: RequestDispatcher.forward()
 - in the jsp page, access the bean
     <%@ page session="true"%>
     <jsp:useBean id="beanName" scope=session  class=... />

In the jsp page, it does not find the bean so it creates a new one.

I can see from my debugging that the session object, before and after the
'forward',
is the same.  However, it does not have the save attributes.  I added debug
print lines
that show the identity of the bean before and after I do the forward() and
that appears
to be the point at which the bean I created is not found and the jsp page
creates a new one.

When control returns from the call to RequestDispatcher.forward(), I was
able to
access the correct instance of the bean.

Why did the jsp page not find the bean the servlet put in the session?

I could really use some help on this and would appreciate any suggestions.


Thanks,
Gary

BTW, I am using Orion 8.2, on NT with JDK 1.2.2


Reply via email to