几秒后Jsp 500错误

时间:2014-05-29 14:31:41

标签: hibernate jsp tomcat

下面是hibernate.cfg.xml

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://ip:3306/database</property>
    <property name="hibernate.connection.username">user</property>
    <property name="hibernate.connection.password">pass</property>
   <property name="hibernate.connection.pool_size">50</property>
   <property name="show_sql">true</property>
   <property name="current_session_context_class">thread</property>

    <mapping resource="user_detail.xml"/>
  </session-factory>

</hibernate-configuration>

下面是HibernateUtil类

private static final SessionFactory sessionFactory;

static {
     try {
         sessionFactory = new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
                 selectData.descLog(""+sessionFactory);
     } catch (Throwable ex) {
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
     }
}

public static Session openSession() {
     return sessionFactory.openSession();
}
下面的

是index.jsp

     String username = "user";
     List<user_detail> list = selectData.getData(username);

                for (user_detail detail: list)
                {
                    divertedRoute = detail.getDivertedRoute();
                    credit = detail.getRate();
                }

这是selectData类

List<user_detail> list = null;
        try{

        Session session = HibernateUtil.openSession();


        Transaction tx=session.beginTransaction();
        Query query = session.createQuery("from user_detail where username = :user");
        query.setParameter("user", username);
        list =  query.list();

        tx.commit();
        session.close();
        }
        catch(Exception e)
        {
            descLog("Exception caught..!!"+e.getMessage());
            writeLog(e);
        }
           return list;

现在的问题是当我从浏览器点击index.jsp然后它运行完美。但是几秒钟后,它给了我500个错误。以下是错误 -

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 38

再次击中后我得到了很好的反应。但为什么会出现这个问题?     显示java.lang.NullPointerException

我检查了hibernate日志并找到了

org.hibernate.exception.JDBCConnectionException: could not execute query

以下是整个堆栈跟踪 -

SEVERE: Servlet.service() for servlet [jsp] in context with path [/smppBalanceDeduct] threw exception [An exception occurred processing JSP page /index.jsp at line 38

35:          //   selectData sData = new selectData();
36:             List<user_detail> list = selectData.getData(username);
37:             selectData.descLog("listing is:"+list);
38:             for (user_detail detail: list)
39:             {
40:                 divertedRoute = detail.getDivertedRoute();
41:                 credit = detail.getRate();


Stacktrace:] with root cause
java.lang.NullPointerException
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:100)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:724)

0 个答案:

没有答案