Elisabeth,

you are not doing a 'forward' in the JSP/Servlet sense of the word, you are
doing a redirect. The redirect causes the web server to send a re-direct
header back to the browser, the browser then does another request to the
server. My guess is that all your problems stem from this. Try using a
RequestDispatcher to forward the request to the JSP and not use re-direct,
the 'forward', forwards the request within the servlet/JSP engine (there is
no round-trip involved - BTW round trips are evil),

Kevin Jones
DevelopMentor

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Elisabeth Freeman
Sent: 11 January 2000 15:47
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

===========================================================================
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