if (requestURI.contains("apple") && requestURI.endsWith("xhtml")) {
if (session == null || session.getAttribute("emid") == null) {
response.sendRedirect("login.xhtml");
} else {
String param = request.getParameter("pname");
String cp = request.getContextPath();
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", cp + "/apple/" + param);
}
}
if (requestURI.contains("apple") && !requestURI.endsWith("xhtml")) {
if (session == null || session.getAttribute("emid") == null) {
response.sendRedirect("login.xhtml");
} else {
String ss[] = requestURI.split("/");
String param = ss[ss.length-1];
request.getRequestDispatcher("apple.xhtml?pname="+param).forward(arg0, arg1);
}
}
arg2.doFilter(arg0, arg1); //line 70
以上代码位于doFilter块中。
我想要完成什么? 1)使用.xhtml扩展名重写URL,例如example.com/apple.xhtml?pname=ipod,如此example.com/apple/ipod。 2)如果session为null,则apple.xhtml页面重定向到login.xhtml。
任务2完成。
由于某些原因,重写不起作用,因为行hsr.getRequestDispatcher(“apple.xhtml?pname =”+ param).forward(arg0,arg1)抛出“java.lang.IllegalStateException:无法调用sendError( )在提交响应后“异常。我做错了什么?
堆栈跟踪
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:456)
at org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:805)
at org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:454)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.apache.catalina.servlets.DefaultServlet.service(DefaultServlet.java:434)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at pcf.CleanUrls.doFilter(CleanUrls.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:417)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)