2014-03-24 25 views
1

我對struts2非常陌生,我試圖遵循tutorial。我正在使用Eclipse和Tomcat服務器來運行應用程序。過濾器標籤在struts2中不被識別

我的過濾器標籤沒有得到認可和相應的操作文件不會called.When我嘗試運行應用程序

http://localhost:8080/Struts2Starter 

它只是說「所請求的資源不可用」 ..

我已經下載了相應的struts2 jar文件並將它們指向WEB-INF/lib。

我有我的web.xml如下

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>Struts2Starter</display-name> 

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

    <welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 


</web-app> 

我有我的struts.xml如下這是在類路徑(src文件夾)

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 

    <struts> 
    <package name="default" extends="struts-default"> 
    <action name="getTutorial" class="org.kowshik.action.TutorialAction"> 
    <result name="success">/success.jsp</result> 
    </action> 

    </package> 

    </struts> 

我真的不知道我錯過了什麼可以幫助我嗎?

+0

有啓動期間或在請求時的任何錯誤? –

+0

no ..我根本沒有得到任何錯誤.. – Sruthi

+0

@Sruthi如果你沒有得到任何錯誤,那麼你很好,資源不可用,因爲沒有這樣的資源。要麼讓struts處理資源或Web服務器。目前沒有其他選擇,您應該知道這一點。 –

回答

0

org.kowshik.action.TutorialAction類在動作配置中不被識別。您應該檢查與操作類相對應的包的名稱。

您已經從網頁內容的根目錄開始您的應用程序。這意味着如果你的根文件夾有一個index.jsp它將被網絡服務器使用,無論struts如何在filter-mapping中配置它,它都會對它進行過濾。該文件內容中最有用的部分是重定向到全功能的struts操作。例如

<% response.sendRedirect("getTutorial.action"); %> 

而且添加該常量到struts.xml,如果你不小心把一個約定插件您WEB-INF/lib文件夾:

<constant name="struts.convention.action.disableScanning" value="true" /> 
+0

我在我的項目中的相應包中有TutorialAction類。我在根文件夾中有一個index.jsp,它不會被調用,而是引發異常每當我在web.xml中包含過濾器時,請求的資源都不可用。 – Sruthi

+0

檢查應用程序已啓動的服務器日誌,它具有資源。 –

+0

你也可以看到這個解決方案http://stackoverflow.com/a/20500298/573032 –