Struts2中无法找到Jsp页面

在struts2中直接访问jsp页面报错:

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]

随后检查web.xml确认配置中的确只是对*.action的url进行了拦截:

 

<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>

我使用的Struts2版本为2.3.4.1,后查阅资料得知,无法访问jsp的原因并不是因为配置有错,而是因为在jsp页面中加入了struts2的标签库,如果需要使用struts2的标签库,那么必须通过action跳转的方式来访问该jsp

 

解决办法:

在struts.xml文件中添加如下action配置:

 

<action name="*">
	<result>/{1}.jsp</result>
</action>

 然后将原有的.jsp结尾的页面通过.action的方式即可正常访问。

如:http://localhost:8080/index.jsp => http://localhost:8080/index.action

 

如果针对单个jsp页面可以这样处理:

 

<action name="index">
    <result>/index.jsp</result>
</action>

 这样也可通过localhost:8080/index.action正常访问

 

你可能感兴趣的:(strtus2)