tomcat error 500...  
Author Message
balgach@gmail.com





PostPosted: 2005-4-29 6:08:00 Top

java-programmer, tomcat error 500... Hello all, i am trying to load a class file into a JSP page and getting
a few errors...what ive got is a simple form, that reads a username,
password, and submits it to a login.jsp file. my login.jsp looks
like:

<%@ page import="IMASOS.UserInterface" %>
<html><head> ... <body>

<%
String uname=request.getParameter("username");
String passw=request.getParameter("password");
UserInterface ui = new UserInterface();
boolean success = ui.login(uname,passw);
if (success) out.println("<h2>User logged in</h2>");
else out.println("<h2>Login Failure</h2>");
%>
</body>

and the error im getting is...

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NullPointerException
IMASOS.UserInterface.login(UserInterface.java:92)
org.apache.jsp.login_jsp._jspService(org.apache.jsp.login_jsp:50)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

 
Wendy Smoak





PostPosted: 2005-4-29 8:21:00 Top

java-programmer >> tomcat error 500... <email***@***.com> wrote:

> Hello all, i am trying to load a class file into a JSP page and getting
> a few errors

> java.lang.NullPointerException
> IMASOS.UserInterface.login(UserInterface.java:92)

What's on line 92 of UserInterface? Something there is throwing the NPE.

--
Wendy



 
Ross Bamford





PostPosted: 2005-4-29 9:13:00 Top

java-programmer >> tomcat error 500... On Thu, 2005-04-28 at 15:08 -0700, email***@***.com wrote:
> Hello all, i am trying to load a class file into a JSP page and getting
> a few errors...what ive got is a simple form, that reads a username,
> password, and submits it to a login.jsp file. my login.jsp looks
> like:

> <%
> String uname=request.getParameter("username");
> String passw=request.getParameter("password");
> UserInterface ui = new UserInterface();
> boolean success = ui.login(uname,passw);
> if (success) out.println("<h2>User logged in</h2>");
> else out.println("<h2>Login Failure</h2>");
> %>
> </body>
>
> and the error im getting is...
> ...
> root cause
>
> java.lang.NullPointerException
> IMASOS.UserInterface.login(UserInterface.java:92)
> org.apache.jsp.login_jsp._jspService(org.apache.jsp.login_jsp:50)
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>

This error is almost certainly caused by one or both getParameter calls
returning null (parameter not defined), which UserInterface.login
doesn't like. You have two options:

First off, in UserInterface.login(String, String), you could check the
parameters against null, and maybe throw an exception or something (to
indicate the user needs to enter both params).

Or, after:

> <%
> String uname=request.getParameter("username");
> String passw=request.getParameter("password");
>

You could do something like

if (uname == null) uname = new String();
if (passw == null) passw = new String();

This should fix the exception, but it's not particularly helpful, since you don't
know whether the user entered an empty name, no name, or what.

Once this is done you'll probably want to find out why the parameters weren't passed
in the first place (are they named correctly in your HTML form?).

Hope that helps,
Ross

--
[Ross A. Bamford] [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ + email***@***.com