tomcat error 500...

B

balgach

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)
 
W

Wendy Smoak

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.
 
R

Ross Bamford

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top