org.apache.jasper.JasperException:处理JSP页面时发生异常

时间:2014-07-23 06:34:41

标签: java jsp tomcat servlets

我的.jsp文件:

<%@page import="lm.BookBean"%> 
<%@page contentType="text/html"%> 
<%@page pageEncoding="UTF-8"%> 
<%@page import="java.sql.*"%> 
<%@ page import="java.io.*,java.util.*,java.sql.*"%> 
<%@ page import="javax.servlet.http.*,javax.servlet.*" %> 
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Library Settings</title> 
  </head>
  <body>
    <jsp:useBean id="book" scope="page" class="lm.BookBean" /> 
    <%book.addSettings(); %> 
  </body> 
</html>  

我的BookBean是:

public int addSettings() { 
  System.out.println("step 1"); 
  Connection con=null; 
  PreparedStatement ps=null; 
  try { 
    con=Database.getConnection(); 
    ps=con.prepareStatement("insert into settings values (?,?,?)"); 
    ps.setInt(1, no_of_books) 
    ps.setInt(2, day_renewal); 
    ps.setInt(3, fine); 
    ps.executeUpdate(); 
  } catch(Exception e) { 
    e.printStackTrace(); 
  } finally { 
    Database.clean(con, ps); 
  } 
  return (Integer) null; 
} 

我遇到了这种错误:

  

HTTP状态500 - 类型异常报告消息说明服务器遇到内部错误()

阻止它完成此请求。

例外:

org.apache.jasper.JasperException: An exception occurred processing JSP page /LRapplication/pages/library_settings.jsp 
   at line 17 <jsp:useBean id="book" scope="page" class="lm.BookBean" /> 
   <jsp:setProperty name="book" property="*"/> <%book.addSettings(); %>   
   Stacktrace:   
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:428)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
    ... 
    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)   root 
      cause 
    java.lang.NullPointerException 
    lm.BookBean.addSettings(BookBean.java:144) 
    org.apache.jsp.LRapplication.pages.library_005fsettings_jsp._jspService(library_005fsettings_jsp.java:87)   
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 
    ...

2 个答案:

答案 0 :(得分:1)

你的堆栈跟踪中有很糟糕的格式。现在它格式有点,请找到以下内容:

java.lang.NullPointerException 
lm.BookBean.addSettings(BookBean.java:144) 

检查BookBean.java的第144行。您正在那里访问空对象。

答案 1 :(得分:0)

  

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

33: 
34:         SimpleDateFormat dateformat = new SimpleDateFormat ("E    yyyy.MM.dd"); 
35: 
36:     Date displaydate1=new Date(date1); 
37:     Date displaydate2=new Date(date2);
38: 
39:       int differenceInDays = (int) ((displaydate2.getTime() - displaydate1.getTime())/(1000*60*60*24));//common method to calculate number of days

堆栈跟踪:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)     javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

根本原因

java.lang.IllegalArgumentException
java.util.Date.parse(Date.java:617)
java.util.Date.<init>(Date.java:274)
org.apache.jsp.CalculateDate_jsp._jspService(CalculateDate_jsp.java:93)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)     javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

  

如何解决此错误,请提供任何解决方法。