Hello World -6ren">
gpt4 book ai didi

java - struts 2 教程中的第一个示例

转载 作者:行者123 更新时间:2023-11-29 07:19:48 24 4
gpt4 key购买 nike

我想开始使用Struts 2框架,我下载Struts 2.2.3 ,然后按照此 tutorial制作第一个示例,但是当我运行具有

的 index.jsp 时
<%@ taglib prefix="s"  uri="/struts-tags" %>
....
<p><a href="<s:url action='hello'/>">Hello World</a></p>
..

发生此异常:

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]

我没有在 web.xml 中指定任何过滤器,因为在创建 Web 应用程序时未创建 web.xml 文件?!仅存在 sun-web.xml 文件。

最佳答案

来自您自己链接的教程。

Step 5 - Add Struts 2 Servlet Filter

To enable the Struts 2 framework to work with your web application you need to add a Servlet filter class and filter mapping to web.xml. Below is the filter and filter-mapping nodes you should add to web.xml.

web.xml Servlet Filter

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

For more information about configuring the deployment descriptor for Struts 2 see web.xml. Note the url-pattern node value is /* meaning the Struts 2 filter will be applied to all URLs for this web application.

你读过吗?创建 web.xml(IDE 通常应该已经完成​​)并按照教程中的说明在其中声明过滤器。

关于java - struts 2 教程中的第一个示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6003024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com