aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "send bean from servlet to jsp " Watch "send bean from servlet to jsp " New topic
Author

send bean from servlet to jsp

Chris Behr
Greenhorn

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:
Servlet:
getServletContext().setAttribute("logonBean", logonBean);
response.setIntHeader("Refresh", 0);
response.sendRedirect(pageName);
JSP:
<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:
Servlet:
HttpSession session = request.getSession(true);
session.setAttribute("logonBean", logonBean);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(pageName);
dispatcher.forward(request, response);
JSP:
<%@ 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: http://aspose.com/file-tools
 
subject: send bean from servlet to jsp