在struts2.0中直接訪問jsp路徑,有時候會出現這樣的錯誤:
Error 500--Internal Server Error
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:52) at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49) at jsp_servlet._report.__customerinfo._jspService(__customerinfo.java:133) at weblogic.servlet.jsp.JspBase.service(JspBase.java:34) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42) at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3242) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
錯誤提示里已經說得很明白:這通常是由於不經由Filter訪問包含struts標簽的jsp頁面導致的。那么,只要通過配置,使得對jsp頁面的訪問請求由Filter過濾轉發即可。
方法1:在strut.xml中配置一個通用Action,通過這個Action轉發到jsp頁面。這個時候,原先訪問jsp的請求路徑就要換成相應的Action路徑了。寫法如下。
<action name="*"> <result>/{1}.jsp</result> </action>
方法2:在web.xml中配置Filter的url-parttern。寫法如下。其中struts2-dispatcher 是已定義的Filter。
<filter-mapping> <filter-name>struts2-dispatcher </filter-name> <url-pattern>*.action </url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2-dispatcher </filter-name> <url-pattern>*.jsp </url-pattern> </filter-mapping>
方法3:在web.xml中配置擴展名。寫法如下。配置完成后,就可以這樣訪問了:http://localhost:8080/yk_cpp/public/index.html
在web.xml中加
<init-param> <param-name>struts.action.extension</param-name> <param-value>html</param-value> </init-param>
在struts.xml中加
<constant name="struts.action.extension" value="html" />
方法4:修改struts.properties文件。去struts2的包里看一下default.properties,里面默認的action是struts.action.extension=action,,(注意有兩個逗號,意思是第二個配置是空)空是全部攔截。在這里修改要攔截的帶擴展名的文件,比如struts.action.extension=action,jnlp,do
我出現這個的問題 我使用了第二種方法解決了。