Struts2 - Статус HTTP 404 - /struts2Test/testAction.action - PullRequest
0 голосов
/ 28 апреля 2020

Я новичок в распорках. Я пытаюсь понять, как это, я видел много уроков и решений, но ничто не может помочь решить мою ошибку. Не могли бы вы помочь мне понять, где я ошибся и что нужно исправить. Ниже приведен мой код.

Моя сеть. 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>

мои распорки. 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>

enter image description here

мой путь

enter image description here

1 Ответ

0 голосов
/ 28 апреля 2020

См. Страницу Как спросить .

В конфигурации S2 вы указываете, что ваши файлы JSP находятся на root веб-содержимого. Это не так, они находятся в каталоге WEB-INF, поэтому ваши результаты должны отражать это, например,

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

Также неясно, как вы развертываете приложение, например контекст приложения. может быть, а может и не быть struts2Test, так что вам нужно это выяснить.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...