Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

send bean from servlet to jsp

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic