我是jsp和servlets的新手。我有一个error.html页面,当我的servlet抛出一个用户定义的异常时,我希望显示该页面,但是我得到了500个inetrnal服务器错误。当我做一个response.sendError时,错误设置正常工作..你能帮帮我吗?代码如下:
if ((username != null) && (username.length() > 0)) {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response");
if (dispatcher != null) {
dispatcher.include(request, response);
}
}
//If user does not enter anything, throw a custom exception
else {
//response.sendError(500, "You did not enter your name");
throw new NameNotEnteredException();
}
我在下面附加了我的web.xml错误配置:
<error-page>
<exception-type>exceptions.NameNotEnteredException</exception-type>
<location>/NameNotEnteredError.html</location>
</error-page>
我已经通过glassfish服务器附加了堆栈跟踪:我希望这是堆栈跟踪你 要求?否则请告诉我如何生成堆栈跟踪?
===========================堆栈跟踪开始================ ================= 信息:hello_servlet_errorhandling在359毫秒内成功部署。 警告:StandardWrapperValve [GreetingServlet2]:PWC1406:用于servlet的Servlet.service()GreetingServlet2引发了异常exception.NameNotEnteredException 在servlets.GreetingServlet2.doGet(GreetingServlet2.java:48) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:734) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) 在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) 在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) 在com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) 在com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 在com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 在com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 在com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 在com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 在com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:532) 在com.sun.grizzly.util.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:513) 在java.lang.Thread.run(Thread.java:662)
==========================堆栈跟踪结束================= ============================