Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

send bean from servlet to jsp

 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!