• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

apache tomcat error

 
Patricia Murphy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey when i try to submit my jsp page in order to access another jsp page i'm getting the following error:

description: The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)


root cause

java.lang.NullPointerException
hospital_administration_system.login.authenticate(login.java:45)
org.apache.jsp.validateuser_jsp._jspService(validateuser_jsp.java:77)
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:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

this id some of my code:

login.java class:

package hospital_administration_system;
import java.sql.*;
import java.io.*;

public class login {

public login() {
}
//method for the database connection
public Connection getConnection()
throws IOException{
Connection conn = null;
try{
DBConnectionManager manager = DBConnectionManager.getInstance();
conn = DriverManager.getConnection("HOSPITALdb");
} catch(SQLException e) {
System.out.println("SQLException: " + e.getMessage());
while((e = e.getNextException()) != null)
System.out.println(e.getMessage());
}
return conn;
}

//method that is called from validateuser.jsp and this checks for the authentic user and password
public boolean authenticate(String user, String password)
throws SQLException, IOException{
String userName = null, passWord = null;
login dbconn = new login();
Statement stmt = dbconn.getConnection().createStatement();
String sql = "SELECT USER_NAME, PASSWORD FROM LOGIN WHERE USER_NAME='" + user + "'" + "AND PASSWORD='" + password + "'";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
userName = rs.getString("USER_NAME");
passWord = rs.getString("PASS_WORD");
}
if(userName != null && passWord != null && user.equals(userName) && password.equals(passWord)){
return true;
} else return false;
}
}

validateuser.jsp class:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<jsp:useBean id="idHandler" class="hospital_administration_system.login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
String userName = request.getParameter("userName");
String passWord = request.getParameter("passWord");
if (idHandler.authenticate(userName, passWord)){
response.sendRedirect("home.jsp");
} else {
response.sendRedirect("login.jsp");
}
%>
</body>
</html>

Any help would be great
Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the stack trace:

hospital_administration_system.login.authenticate(login.java:45)


So you're getting an NPE at line 45 of login.java. What's at that line? Why is something null that shouldn't be?

And please use UBB Code tags when posting code.
[ February 08, 2007: Message edited by: Bear Bibeault ]
 
Patricia Murphy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 45 in login.java is as follows:



any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way that statement can NPE is if the getConnection() method returns null.

Time to dig in, backtrack and diagnose why that's happening.
 
xuan zhou
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello poster , I have meet this trouble . I also dislike it . And afraid so many error displayed .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic