异常分析:以上的配置及文件中,如果采用 http://ip:port/SayHello.jsp,那么会出现前面所提到的异常。如果采用http://ip:port/SayHello.action 进行访问,那么正常。
原因:如果想要在jsp文件中,采用 struts的tag,那么必须通过web.xml所配置的过滤器访问文件,否 则会有异常,即 之前所出现的异常。
解决方案:
方案一:
采用 http://ip:port/SayHello.action 访问
方案二:
将web.xml 的过滤器,从 *.action 修改为: /*
方案三:
修改SayHello.jsp 文件,不使用 struts 的标签。
<!--EndFragment-->
我最终采取方案如下: 在web.xml中如下配置
1.The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Strut
2.s tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher n
3.eeded for this tag. - [unknown location]
解决:
web.xml 中添加一个filter
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/action/*</url-pattern>
</filter-mapping>
解决Struts2在JSP文件中使用异常的问题

本文详细介绍了在使用Struts2框架的JSP文件中遇到异常时的解决办法,包括三种解决方案:采用action路径访问、修改web.xml配置、或者避免使用Struts2标签。重点在于确保Struts2框架的过滤器能够正确初始化,以便在JSP文件中使用Struts2的tag。最后,通过在web.xml中添加过滤器配置解决了问题。
3935

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



