Beth,
Two items, assuming that this is a cut and paste from your code....
Regarding the application scope "systembean" object:
> getServletContext().setAttribute("systembean", systemBean);
> <jsp:useBean id="systemBean" scope="application" class="beans.SystemBean"
/>
Note that the id you use in the usebean tag is not the same as the string
you use as
the key when adding the item to the servlet context. (The 'b' in
"systembean" is
capitalized in one case.) The JSP tag, therefore, is probably creating a
new instance
of the class and adding it to the servlet context. That is why none of the
values are
present.
It not quite as clear what may be going wrong with the bean added to the
session.
I would suggest, however, that when creating the session within the
scriptlet in the
JSP, you use request.getSession(false) - this will help to identify if the
JSP is
using a preexisting session (it should be) or creating a new one altogether.
-AMT
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Elisabeth Freeman
> 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
>
===========================================================================
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