错误404;类型状态报告; description请求的resorce不可用我的struts2应用程序

时间:2015-06-24 11:49:15

标签: java jsp tomcat struts2

执行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";


}

}

1 个答案:

答案 0 :(得分:0)

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

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