File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes send bean from servlet to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "send bean from servlet to jsp " Watch "send bean from servlet to jsp " New topic

send bean from servlet to jsp

Chris Behr

Joined: Jun 12, 2001
Posts: 17
I have a jsp page that has an html from that does a post to a servlet. The servlet then takes the data and puts it into a bean and then send it to another jsp page. I was using the following code:
getServletContext().setAttribute("logonBean", logonBean);
response.setIntHeader("Refresh", 0);
<jsp:useBean id="logonBean" class="logon.LogonBean" scope="application" />
This was working but I read in this forum that using servletContext could cause problems if I have more than one user at a time so I decided to use HttpSession and changed my code to this:
HttpSession session = request.getSession(true);
session.setAttribute("logonBean", logonBean);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(pageName);
dispatcher.forward(request, response);
<%@ page session="true" %>
<jsp:useBean id="logonBean" scope="session" class="logon.LogonBean" />
The problem is that it doesn't work now. If I use the requestDispatcher instead of redirect all I get in the browser is a page not found with the servlet as the url. If I go back to using the redirect the jsp page blows up from apparently not being able to read the bean. Does anyone see anything obvious that I am doing wrong or give me suggestions to try.
I agree. Here's the link:
subject: send bean from servlet to jsp
It's not a secret anymore!