Tomcat在部署servlet时挂起

时间:2014-05-11 12:00:59

标签: java tomcat servlets

我在运行servlet时遇到此错误,如果患者实例存在,我想将我的servlet重定向到JSP页面

    SEVERE: Servlet.service() for servlet [NewServlet] in context with path [/WebApplication11] threw exception
java.lang.NullPointerException
at mypackage.Hospital.SearchPatient(Hospital.java:118)
at controller.NewServlet.processRequest(NewServlet.java:45)
at controller.NewServlet.doGet(NewServlet.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)

这是我的新servlet.java的代码,我正在制作一个医院类的实例,然后想要根据ID搜索患者。 newServlet.java

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        int id = Integer.parseInt(request.getParameter("Searchpatient"));
        HttpSession session = request.getSession();

        Hospital h = new Hospital();
        Patient p = h.SearchPatient(id);
        if (p != null) {
            session.setAttribute("name", "search");
            RequestDispatcher rd = request.getRequestDispatcher("manu.jsp");
            rd.forward(request, response);
        } else {
            session.setAttribute("name", null);
            RequestDispatcher rd = request.getRequestDispatcher("manu.jsp");
            rd.forward(request, response);
        }        

0 个答案:

没有答案