Hmm. Well, I'm not running on a cluster, but perhaps it is a URL issue - I am
using "localhost" and perhaps there is a mixup with that and 127.0.0.1 that is
causing the beans to be stored in the wrong session.

I did a quick test... at the bottom of the JSP, I set the user, username and
useremail and then create a link to a second JSP that does *exactly* the same
thing as the first: gets the systembean from the servlet context and the
userbean from the session.  The userbean values are set in the second JSP!  So
it's not a problem with no session persistence.

I'll experiment with the URLs and see if that's it.

Thanks,
Beth

Tabrez wrote:

> This can happen if the servers that you are using are a cluster and the
> redirect sends the brower to another server in the cluster (and no session
> persistence is available). The new server has no access to the session and
> hence creates a new session and you're bean is not available.
>
> Tabrez
>
> -----Original Message-----
> From: Elisabeth Freeman [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 11, 2000 9:47 AM
> To: [EMAIL PROTECTED]
> Subject: help!
>
> 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