Java 在我的第一个Struts2项目中使用HTTP 404状态代码
我在第一个Struts2项目中遇到了HTTP404状态码问题。我尝试了很多方法,但仍然没有解决问题。如果有任何错误,请检查我的代码和项目结构Java 在我的第一个Struts2项目中使用HTTP 404状态代码,java,struts2,Java,Struts2,我在第一个Struts2项目中遇到了HTTP404状态码问题。我尝试了很多方法,但仍然没有解决问题。如果有任何错误,请检查我的代码和项目结构 EclipseNeon.3发行版(4.6.3) struts-2.3.32 jdk1.8.0_131 apache-tomcat-8.0.43 项目浏览器: struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache
- EclipseNeon.3发行版(4.6.3)
- struts-2.3.32
- jdk1.8.0_131
- apache-tomcat-8.0.43
<?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>
<?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>
我尝试过的在线解决方案:
这一个与我的问题非常相似,但对我没有帮助。导入jar包
commons-lang3-x.x.jar
而不是commons-lang-x.x.jar
您错过了包名。您是否可以尝试使用下面的URL“”仍然无法使用您的URL。Jsp文件与WEB-INF
和META-INF
处于同一级别。我现在处境非常尴尬。我只是注意到您正在使用commons-lang-2.4.jar
。它应该是commons-lang3-3.2.jar
Wooow!你让我开心!它正在使用commons-lang3-3.2.jar
。您能解释一下这两个版本的commons lang
软件包之间的区别吗?您可以在这里查看好的,非常感谢。我已经编辑了你的答案,你可以接受它或者自己编辑。我试过了,它不起作用。你知道为什么我们把它保持在配置下面吗/jsp我尝试在没有struts.xml
文件中的/index.jsp
和web.xml
中的
的情况下运行该项目。我得出的结论是,只要将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>
<%@ 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>
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;
}
}