【问题标题】:First example in struts 2 tutorialstruts 2 教程中的第一个示例
【发布时间】:2011-05-14 16:03:39
【问题描述】:

我想开始使用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 文件存在。

【问题讨论】:

    标签: java jsp struts2


    【解决方案1】:

    来自您自己链接的教程。

    第 5 步 - 添加 Struts 2 Servlet 过滤器

    要使 Struts 2 框架能够与您的 Web 应用程序一起工作,您需要添加一个 Servlet 过滤器类和过滤器映射到 web.xml。下面是您应该添加到 web.xml 的过滤器和过滤器映射节点。

    web.xml Servlet 过滤器

    <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 通常应该已经完成​​)并按照教程中的说明在其中声明过滤器。

    【讨论】:

    • 是的,我做到了,我提到构建项目时没有创建 web.xml 文件的问题,我从另一个项目复制 web.xml 文件并将其添加到该项目中,并且添加过滤器但出现另一个异常,即“无法加载配置。-bean - jar:file:/D:/f/alaa%20college/year%204/2ed%20semester/Advance%20SW%20application/struts/FirstStrutsTest /build/web/WEB-INF/lib/struts2-gxp-plugin-2.2.3.jar!/struts-plugin.xml:8:162 "
    • 这是一个不同的问题。问一个新问题。
    【解决方案2】:

    如果您从 Struts2 开始,请查看 Maven Archtypes。 这里描述了它是如何工作的。

    4 Easy Steps to create a Java based Web Application with Struts2 and jQuery

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-28
      • 2011-07-20
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 2012-02-01
      相关资源
      最近更新 更多