【问题标题】:Struts2 - HTTP Status 404 - /struts2Test/testAction.actionStruts2 - HTTP 状态 404 - /struts2Test/testAction.action
【发布时间】:2020-08-11 22:26:31
【问题描述】:

我是新来的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>struts2Test</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.filter.StrutsPrepareAndExecuteFilter</filter- 
 class>
             </filter>
             <filter-mapping>
              <filter-name>struts2</filter-name>
              <url-pattern>/*</url-pattern>
             </filter-mapping>
            </web-app>

我的 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="test" extends="struts-default">
        <action name="testAction" class="TestAction">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
</struts>   

我的动作课

public class TestAction {
    public String execute() {
        System.out.println("in execute method");
        return "success";
    }
}

我的成功jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>success</h1>
    </body>
    </html>

我的错误jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"%>
        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="ISO-8859-1">
        <title>Insert title here</title>
        </head>
        <body>
        <h1>error.jsp</h1>
        </body>
        </html>

我的路

【问题讨论】:

  • 如果您使用的是 Eclipse,This 答案将很有用。这是一个新手教程。

标签: java xml jsp struts2


【解决方案1】:

请查看How to Ask 页面。

在 S2 配置中,您指出您的 JSP 文件位于 Web 内容的根目录。它们不是,它们位于 WEB-INF 目录中,因此您的结果应该反映这一点,例如,

<result name="success">/WEB-INF/success.jsp</result>

也不清楚您是如何部署应用程序的,例如,应用程序上下文可能是也可能不是 struts2Test,因此您也需要弄清楚这一点。

【讨论】:

  • 实际上我没有向库中添加任何内容,当我添加时它工作正常。我也会试试你提到的。感谢您的回复:)
【解决方案2】:

您的应用程序无法访问该 URL,因为您没有为您的操作类扩展 ActionSupport 类。尝试扩展它。

【讨论】:

    猜你喜欢
    • 2014-10-15
    • 2018-03-05
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多