首页 > 解决方案 > struts 2中未找到资源错误

问题描述

我正在尝试使用 struts 执行一个基本的 Web 应用程序,但没有找到资源错误,我什至无法显示 index.jsp 文件。我应该怎么办 ?

下面是我的 web.xml 文件

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>Struts2Starter</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>sturts2</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>

下面是我的 struts.xml 文件

struts.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts  
    Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> 

    <struts>
    <package name="default" namespace = "/tutorials" extends="struts-default">      
         <action name="getTutorial" class = "com.struts.TutoralAction" >             
            <result name = "success">/success.jsp</result>
            <result name = "failure">/failure.jsp</result>
            </action>
     </package>
     </struts> 

下面是我的动作课

TutorialAction.java

     package com.struts;

      import com.struts.service.TutorialService;

      public class TutoralAction {
       private String bestTutorial;
       public String execute() {
        TutorialService tutorialService = new TutorialService();
         setBestTutorial(tutorialService.getBestTutorial());
         return "success";
           }
       public String getBestTutorial() {
         return bestTutorial;
        }
         public void setBestTutorial(String bestTutorial) {
            this.bestTutorial = bestTutorial;
            }
          }

标签: struts2

解决方案


推荐阅读