Struts2没有加载我的webapp ... 404错误?

时间:2015-04-01 00:46:27

标签: java jsp tomcat jar struts2

我是Struts2的新手,无法在eclipse /浏览器中运行涉及tomcat的任何东西。当我在web.xml文件中映射servlets / jsp时,Tomcat正常工作,但是当我尝试切换到struts2时,我无法使其工作。当我尝试在服务器上运行时,它甚至不会进入我的索引jsp ...只是加载404错误。我跟着一个在线教程,因为我无法让我的应用程序运行我的课程和我无法运行的教程。这是我添加到tomcat lib / build path jars的jar文件 -

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>

struts 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的任何想法?

2 个答案:

答案 0 :(得分: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 :(得分:1)

过滤器类org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter属于Struts2,但您使用的是struts1 jar文件struts-core-1.3.10.jar

正如Ravi建议的那样,从Struts-2.3.20

下载Jar文件
相关问题