严重: Servlet.service() for servlet jsp threw exception
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.index_jsp._jspx_meth_s_005faction_005f0(index_jsp.java:128)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
出现以上错误原因是:
页面上使用struts标签如:
<%@taglib uri="/struts-tags" prefix="s"%>
<s:action name="cus_like" namespace="/" >
<s:param name="val" value="123456456"></s:param>
</s:action>
解决如上在web.xml过滤struts过滤器的时候过滤action 同时也过滤jsp
<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>
后台代码:
public class CusAction{
public String val;
public void like(){
//<s:param ></s:param>是以request方式的值的,而不是以参数传值
/*
* 用reqeust.getParameter 是无法 取到值得
*
*/
System.out.println("直接赋值"+val);
System.out.println("request取值"+ServletActionContext.getRequest().getAttribute("val"));
}
}
本文探讨了在使用Struts2框架时遇到的一个常见问题:在JSP页面中使用Struts2标签导致的异常。问题核心在于Struts2标签未能正确初始化,通常是因为缺少对应的过滤器配置。文中详细解释了解决方案,即如何在web.xml中配置Struts2过滤器,确保其同时应用于.action和.jsp文件。
185

被折叠的 条评论
为什么被折叠?



