I am forwarding to a JSP from a servlet, and attempting to put one bean
in the application scope (by putting it in the servlet context) and one
bean in the session.

The JSP can see the bean in the servlet context, but the values that I
set in it before the forward are not there, and the JSP can't see the
session bean at all (ie, it's null when I retrieve it from the session.

Here's a code snippet.  Any help would be much appreciated!  Please copy
my email address when responding as I only get the digest format of the
mailing list.

Thanks, Beth

Here's the servlet code:

         SystemBean systemBean = new SystemBean();
         getServletContext().setAttribute("systembean", systemBean);
         String scheme = request.getScheme();
         String host = request.getServerName();
         int port = request.getServerPort();
         systemBean.setServletPath(scheme, host, port);
         systemBean.setJspPath(scheme, host, port);

         String user = request.getParameter("user");
         String password = request.getParameter("password");

         HttpSession theSession = request.getSession(true);
         UserBean userBean = new UserBean();
         userBean.identity.setUser(user);
         userBean.identity.setUserName(user);
         userBean.identity.setUserEmail("[EMAIL PROTECTED]");
         theSession.putValue("userbean", userBean);

         response.sendRedirect("http://" + host + ":" + port +
"/examples/jsp/Here.jsp");

and here's the JSP code:

<%@ page info="Test JSP"
    import="beans.UserBean"
    errorPage="../Error/Error.jsp" %>
<jsp:useBean id="systemBean" scope="application"
   class="beans.SystemBean" />
<%
 String errorMsg = "";
 HttpSession mySession = request.getSession();
 if (mySession == null) {
  errorMsg += "Session is null<BR>";
 }

 if (systemBean == null) {
  errorMsg += "System bean is null<BR>";
 }

 UserBean userBean = (UserBean) mySession.getValue("userbean");
 if (userBean == null) {
  errorMsg += "User bean is null<BR>";
 }

%>

The result is that the system bean is NOT null, but the user bean is.
However, the values in the system bean ARE null.   I tried using a
usebean directive for the userBean as well, and got the same results.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to