java - 我的第一个 Struts2 项目出现 HTTP 404 状态代码

标签 java struts2

我在第一个 Struts2 项目中遇到了 HTTP 404 状态代码问题。我已经尝试了很多方法,但仍然没有解决问题。任何人都可以检查我的代码和项目结构是否有任何错误?

  • Eclipse Neon.3 版本 (4.6.3)
  • struts-2.3.32
  • jdk1.8.0_131
  • apache-tomcat-8.0.43

项目资源管理器:

enter image description here

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>
<constant name="struts.devMode" value="true" />
   <package name="helloworld" extends="struts-default">

      <action name="index">
            <result >/index.jsp</result>
      </action>

      <action name="hello" 
            class="com.tutorialspoint.struts2.HelloWorldAction" 
            method="execute">
            <result name="success">/HelloWorld.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://java.sun.com/xml/ns/javaee" 
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">

   <display-name>Struts 2</display-name>
   <welcome-file-list>
      <welcome-file>index.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>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
</head>
<body>
   <h1>Hello World From Struts2</h1>
   <form action="hello">
      <label for="name">Please enter your name</label><br/>
      <input type="text" name="name"/>
      <input type="submit" value="Say Hello"/>
   </form>
</body>
</html>

HelloWorld.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
   Hello World, <s:property value="name"/>
</body>
</html>

HelloWorldAction.java

package com.tutorialspoint.struts2;

public class HelloWorldAction{
   private String name;

   public String execute() throws Exception {
      return "success";
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
}

enter image description here

我尝试过的在线解决方案:

HTTP 404 error in my first Struts2 application

这个问题与我的问题非常相似,但它对我没有帮助。

最佳答案

导入jar包commons-lang3-x.x.jar而不是commons-lang-x.x.jar

关于java - 我的第一个 Struts2 项目出现 HTTP 404 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43929097/

相关文章:

java - 服务器端 - 进度条

java - Struts2+ Spring : Request Paremeters dont get reset in Action objects?

java - 本地单元测试:读取生产资源时,getResourceAsStream

java - Java 8 的 Maven 错误

java - 如何从依赖其他方法获取数据的方法中获取数据?

SharePoint 2007 中的 Java/JSP 编码

jquery - Struts2 jquery插件用整个页面的HTML响应ajax请求

java - 我如何阻止这种用石板替换特殊板的能力?

java - 当表有八列时,在数据库条目中搜索匹配项

java - 将表单提交到 Struts 操作后,在 DisplayTag 上将页面设置为 1