HTTP状态500 - 在第15行处理JSP页面/second.jsp时发生异常

时间:2015-06-26 12:34:01

标签: java jsp

我在jsp web项目上有四个页面供学生显示来自DB的详细信息..  我使用过tomcat web服务器。

的index.html

<body>
    <h1> Student Search Page</h1>
    <form action="second.jsp">
        <h2> Enter id to search details</h2>
        <input type=text name=ID1 /> <br/>
        <input type=submit value=Search />
        </form>
</body>

second.jsp

   

<body>
   <%
   String id =(request.getParameter("ID1"));
   StudentDAO std=new StudentDAO();
      Student s=std.searchinfo("id");

   %>
   <h1> <%=s.showStudent()%></h1>
</body>

Student.java

 import java.io.*;

 public class Student implements Serializable {

String name; 
String id1,phone,clas;
Student(String  id,String n,String c,String ph)
{
     name=n;
     id1=id;
     phone=ph;
    clas=c;
}
public String showStudent()
{
   return  "Name: "+name+" Address: "+clas+" Phone: "+phone+" ID"+id1;
}

}

studentDAO.java

import java.sql.*;

import java.io.*; 

public class StudentDAO implements  Serializable {

Connection conn;
    PreparedStatement stmt;

public Student searchinfo(String id)
{
    Student studentinfo=null;

try{

String url="jdbc:ucanaccess://C:\\Users\\Asim Iqbal\\Documents\\STUDENT.accdb";
conn = DriverManager.getConnection(url);
String sql= "SELECT * FROM StudentDetails WHERE ID=?";
            stmt = conn.prepareStatement(sql);
            stmt.setString(1,id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
ResultSet rs= null;
        try {
            rs = stmt.executeQuery();
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
        try {
            while (rs.next())
            {
               String i=rs.getString("ID");
               String nam=rs.getString("Name");                  
               String ph=rs.getString("Phone");
               String clas=rs.getString("Class");
                studentinfo=new Student(i,nam,ph,clas);
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
        return studentinfo;
 }


}

这是Stacktrace和根本原因..

堆栈跟踪:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:4
 76)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

 java.lang.NullPointerException

Student.StudentDAO.searchinfo(StudentDAO.java:35)

org.apache.jsp.second_jsp._jspService(second_jsp.java:104)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

注意Apache Tomcat / 8.0.23日志中提供了根本原因的完整堆栈跟踪。

3 个答案:

答案 0 :(得分:0)

我不确定你面临的错误。你可以在这里粘贴错误,这样我就可以帮到你了。但是通过查看你的JSP页面我可以说下面的行中有语法错误&#34; &LT;%= s.showStudent()%&GT;&#34 ;.在&lt;%=和s.showStudent()%&gt;之间留出空格EX:&#34;&lt;%= s.showStudent()%&gt;&#34;并尝试

您能否确认您是否可以从数据库中检索数据? Student对象为null所以你得到这个错误我认为是

谢谢,

答案 1 :(得分:0)

org.apache.jasper.JasperException:在第15行处理JSP页面/second.jsp时发生异常

15:学生s = std.searchinfo(&#34; id&#34;);

bros05,这是主要的错误...

答案 2 :(得分:0)

您的ID1属性未从index.xhtml传递到second.jsp.So您将空值传递给StudentDAO.java,而后者又获取空指针异常。

在index.xhtml中尝试以下修复

<input type=text name="ID1" />