This question already has an answer here:
Unable to get Struts2 Hello World to work using Eclipse and Maven
                                
                                    (1个答案)
                                
                        
                                4年前关闭。
            
                    
执行struts2应用程序时出现404错误。我在apache tomcat 8上运行了该应用程序,并且正在使用eclipse。我在浏览器中的URL末尾附加了/Tutorials/getTutorial.action,该控件应将控件转移到success.jsp,仍然出现404错误。我的代码是
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>
<package name="default" extends="struts-default" namespace="/Tutorials">
<action name="getTutorial" class="org.gurjot.javabrains.action">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>


Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>StartingWithStruts2</display-name>
 <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>


FirstAction.java

package org.gurjot.javabrains.action;
public class FirstAction {
public String execute()
{ System.out.println("hi");
   return "success";


}

}

最佳答案

在struts.xml中,尝试添加类名称

<action name="getTutorial" class="org.gurjot.javabrains.action.FirstAction">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>

09-30 15:18
查看更多