Garry Fisher wrote:
>
> Can anybody help me with the following problem?
>
> I have a JSP, which is the first page to be displayed; the JSP should create
> a ValidateBean Object.
>
> When the submit button is pressed the servlet FormValidate is called to do
> some validation processing. This mechanism all works ok but when I try to
> access the ValidateVBean object in the servlet I get a NULL POINTER
> EXCEPTION error because it cannot see the bean created in the JSP. I have
> checked that the JSP and server are accessing the same session and they are.

Are you absolutely sure they use the same session? A common reason for
"lost session data" between a JSP page and a servlet is that the JSP page
and the servlet are actually in different servlet contexts (web applications).
And contexts don't share session data.

A context is mapped to a URI prefix, like /foo. If you invoke the JSP page
with a URI like /foo/myPage.jsp, and the servlet with /servlet/myServlet,
you are actually invoking resources in two different contexts. To fix this,
invoke the servlet as /foo/servlet/myServlet, or create a URL mapping for
the servlet so it can be invoked as /foo/myServlet.

Also, the following scriptlet is redundant:
> <% session.putValue("validate", validate); %>

The <jsp:useBean> action you use to create the bean also saves it in the
session scope, so you don't have to do it again.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to