【发布时间】:2016-10-20 20:03:30
【问题描述】:
我正在尝试关注this 教程,了解如何开始使用 Struts。
我遵循了确切的步骤,但最后我得到了这个错误HTTP Status 404 - /Struts2-HelloWorldExample/
我知道 404 错误意味着我能够与服务器通信,但服务器找不到我请求的内容。我怀疑我的库有问题,但我在解决同一问题的解决方案中找不到任何东西。
我的java代码:
package com.aziz;
public class HelloWorldExample {
private String name;
public String execute() throws Exception {
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Struts 2 - Hello World Example</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>
你好.jsp:
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
Hello <s:property value="name"/>!
</body>
</html>
index.jsp:
<!DOCTYPE html>
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
<h1>Hello World Example</h1>
<form action="hello">
<label for="name">Enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
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="default" namespace="/" extends="struts-default">
<action name="hello"
class="com.aziz.HelloWorldExample">
<result name="success">hello.jsp</result>
</action>
</package>
</struts>
我不确定我在做什么是对还是错,但我只是手动添加了我从here(完整发行版)下载的 WEB-INF/lib 文件夹中的 struts 库,所以我有该文件夹中的这些 JAR:
最后一件事,我没有错误,但我的标记上有这些警告:
我已经检查了这个错误,我知道这是什么意思,因为当我看到解决方案时,有人说我需要决定是否以及将哪些库复制到项目属性中的 WAR -> Java EE 模块依赖项。但是在我的项目属性中,没有 Java EE Module Dependencies 之类的东西。 我真的需要你的帮助。 提前致谢。
【问题讨论】:
-
尝试修改这个 ->
/WebContent/index.jsp -
不要包含完整发行版中的所有 jar。如果您不知道要包含什么内容,请下载
Essential Dependencies Only分发版。 -
您可能在 Eclipse 中有错误的项目配置和错误的依赖项。使用 Maven 重新创建一个项目。
标签: java jsp jakarta-ee struts2 http-status-code-404