登录页面使用struts标签的jsp页面。当程序出现404,500错误时,跳转到登录页面,但是会提示The Struts dispatcher cannot be found错误。
严重: Exception Processing ErrorPage[errorCode=404, location=/login.jsp]
org.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:447)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:424)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:144)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:107)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
... 19 more
我的web.xml文件是这样配置的
<!-- 配置struts2过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!-- 配置初始页面 -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<!-- 配置错误处理 -->
<error-page>
<error-code>404</error-code>
<location>/login.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/login.jsp</location>
</error-page>
------解决思路----------------------
你的struts.xml 文件有没有继承 struts-default
------解决思路----------------------
、
比如说你当前的访问的页面路径是a目录下面的,然后你想跳到b目录下的login页面,可以直接重定向么?那样跳转的还是a目录下的login,结果就报404,我以前也遇到这种问题。
应该先上一级目录或者在xml重新配置一下。
------解决思路----------------------
这情况正常啊,要不然你页面出现500了,直接跳转到了登陆页,但你不知道错误出现在哪里,怎么改?
下次难道还500么?
------解决思路----------------------
你这是求实现的方法是么?
500错误,其它层抛出异常,在action层捕获异常,然后try catch里面重定向跳转。
404错误,struts.xml配置一个默认跳转的配置,无对应的也是重定向跳转。
至于代码,我这用的开发环境是Spring Tool Suite,自己的笔记本没带,晚上给你发。
------解决思路----------------------
首先看看错误处理配置这里有没有生效,如果有效的话,出现404错误,那可能是/login.jsp这里的路径有错误。500错误的话是你页面出现错误。总之,你先检查获取错误配置有没有生效。
------解决思路----------------------
既然配置生效的话, 却没有捕获到异常,可能是10楼说的问题。
------解决思路----------------------
百度搜索 struts default-action-ref
------解决思路----------------------
你的login页面的errorPage=true 设置了没有???
------解决思路----------------------
刚才会说错了 应该是这样
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isThreadSafe="true" %>