Problem sending bean from servlet to jsp

I have a html page that submits imformation from a form to a servlet. The servlet then creates a bean and uses the sendRedirect to send it to a jsp page. I read somewhere that tomcat sometimes loses the session so I added the following code:

<% if(session.isNew()) { %>

Session is new

<% } %>

but the message never appeared so I am guessing that is not the problem. Here is the code that I use in the servlet:

guestBean = new GuestBean();

guestBean.setName("Chris");

HttpSession session = request.getSession(true);

session.putValue("guestBean", guestBean);

response.sendRedirect("/cbweb/GuestThank.jsp");

and here is the code I have in the jsp to display the name:

<jsp:useBean id="guestBean" class="Guest.GuestBean" scope="session" />

<%= guestBean.getName() %>

All I get is "null", I even considered there might be something wrong with the bean so I coded the following to test the bean:

<jsp:setProperty name="guestBean" property="name" value="Test name" />

and the name came out ok, so I am pretty sure the problem is that the bean isn't getting passed from the servlet to the jsp. If anyone has any suggestions I am willing to try anything.

Thanks

[1364 byte] By [OmahaLancer] at [2007-9-26 3:16:49]
# 1

The session that you're putting the bean into from the Servlet is the HttpSession, not the same "session" that the bean would reside in when instantiated from a JSP.

When you use the useBean tag and set the scope attribute to session, it means that the bean will be available to JSPs throughout the user's session, it does not mean that the bean is placed into the HttpSession.

I can't think of an easy way to share a session bean between Servlets and JSPs. You could place a "handle" to the bean into the HttpSesssion from a JSP, and then retrieve it from the HttpSesssion from your Servlet. However, this doesn't sound like a very good solution though. I'd recommend sharing the data somehow else.

-Derek

beattris at 2007-6-29 11:29:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Did you ever find a solution to this problem. I am currently having the same issue where my JSP page does not get access to the bean that I saved in the servlet HttpSession.Please reply to me and let met know.Harry
Harry_O_Z at 2007-6-29 11:29:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...