2015-04-01 32 views
0

我是一個Struts2的新手,我無法在eclipse /瀏覽器中運行任何涉及tomcat的東西。當我只是在web.xml文件中映射servlets/jsp時,Tomcat工作正常,但當嘗試切換到struts2時,我無法使其工作。當我嘗試在服務器上運行它甚至沒有去我的索引jsp ...只是加載404錯誤。我跟着一個在線教程,當我無法讓我的應用程序運行我的課程和教程我無法運行。以下是我已經加入到Tomcat的lib的jar文件/構建路徑罐子 -Struts2未加載我的webapp ... 404錯誤?

asm-5.0.2.jar    
asm-commons-5.0.2.jar  
asm-tree-5.0.2.jar   
commons-fileupload-1.3.1.jar  
commons-io-2.2.jar  
commons-lang3-3.2.jar 
commons-logging-1.1.3.jar 
commons-logging-api-1.1.jar 
freemarker-2.3.19.jar 
javassist-3.11.0.GA.jar 
ognl-3.0.6.jar  
struts-core-1.3.10.jar  
struts2-dojo-plugin-2.3.20.jar  
xwork-core-2.3.20.jar  

過濾器添加到web.xml中 -

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

支柱XML -

<?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> 
<constant name="struts.devMode" value="true" /> 
<package name="helloworld" extends="struts-default"> 

    <action name="hello" 
     class="com.struts2.files.HelloWorldAction" 
     method="execute"> 
     <result name="success">/HelloWorld.jsp</result> 
    </action> 
</package> 
</struts> 

任何想法,爲什麼我試圖運行應用程序時得到404?

+0

使用瀏覽器開發人員工具下載JAR文件來查看請求。我想也許「/HelloWorld.jsp」是一個錯誤的路徑。 – MageXellos 2015-04-01 00:52:00

+0

PS:在「重定向」中設置屬性,然後您可以在Developer tool中看到您的請求。否則,它將使用默認的轉發方法。 – MageXellos 2015-04-01 00:53:37

回答

1

我想,您已將錯誤的struts-core-1.3.10.jar添加到您的類路徑。這可能屬於Struts 1.x。您需要包含來自Struts 2框架的最新struts2-core-2.x.x.jar

典型的Struts 2應用程序在WEB-INF/lib目錄下有以下jar。

commons-fileupload-1.2.1 
commons-io-1.3.2 
commons-logging-1.1 
freemarker-2.3.13 
junit-3.8.1 
ognl-2.6.11 
xwork-2.1.2 
struts2-core-2.1.6 
struts2-convention-plugin-2.1.6 (if using annotations) 

嘗試從struts.apache.org下載最新的罐子。

1

過濾器類org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter屬於Struts2,但使用的是struts1的jar文件struts-core-1.3.10.jar

由於拉維認爲,從Struts-2.3.20