2011-05-14 73 views
1

我想開始使用Struts 2框架,我下載Struts 2.2.3 ,並遵守本tutorial做第一個例子,但是當我運行它有第一例2教程

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

這中的index.jsp發生異常:

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應用程序並沒有在web.xml中指定任何過濾器,因爲沒有創建web.xml文件沃斯?!只有sun-web.xml文件存在。

回答

5

來自你自己鏈接的教程。

第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通常應該已經完成​​了)並根據教程中的說明在那裏聲明過濾器。

+0

是我沒有,我提到,當我生成項目的web.xml文件還沒有產生的問題,我做的web.xml文件的副本,從另一個項目,並將其添加到該項目,並添加過濾器,但另一例外發生,這是 「無法加載配置 - 豆 - 罐子:文件:/ d:/ F /阿拉%20college /年%204/2ED%20semester /提前%20SW%20application /支柱/ FirstStrutsTest /編譯/網絡/ WEB-INF/lib目錄/ Struts2的-GXP-插件-2.2.3.jar /struts-plugin.xml:8:162「 – palAlaa 2011-05-14 16:22:43

+0

這是一個不同的問題。問一個新問題。 – BalusC 2011-05-14 16:25:34