我想开始使用Struts 2框架,我下载Struts 2.2.3 ,并按照本教程 制作第一个例子,但是当我运行index.jsp时
<%@ taglib prefix="s" uri="/struts-tags" %>
....
<p><a href="<s:url action='hello'/>">Hello World</a></p>
..
Run Code Online (Sandbox Code Playgroud)
发生此异常:
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]
Run Code Online (Sandbox Code Playgroud)
我没有在web.xml中指定任何过滤器,因为在创建Web应用程序时没有创建web.xml文件?只存在sun-web.xml文件.
从你自己链接的教程.
第5步 - 添加Struts 2 Servlet过滤器
要使Struts 2框架能够与Web应用程序一起使用,您需要添加Servlet过滤器类和过滤器映射到web.xml.下面是您应该添加到web.xml的过滤器和过滤器映射节点.
web.xml Servlet过滤器
Run Code Online (Sandbox Code Playgroud)<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>/*</url-pattern> </filter-mapping>有关为Struts 2配置部署描述符的更多信息,请参阅web.xml.请注意,url-pattern节点值为/*,这意味着Struts 2过滤器将应用于此Web应用程序的所有URL.
你读过它吗?创建web.xml(IDE通常应该已经完成)并根据教程中的说明在其中声明过滤器.
| 归档时间: |
|
| 查看次数: |
4478 次 |
| 最近记录: |