Java struts项目无法正常工作的未知原因?
我做的每件事都是正确的,但它不起作用 web.xmlJava struts项目无法正常工作的未知原因?,java,xml,struts2,Java,Xml,Struts2,我做的每件事都是正确的,但它不起作用 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:sch
<?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>m2r</display-name>
<welcome-file-list>
<welcome-file>weldcome.jsp</welcome-file>
<welcome-file>index.jsp</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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/hello</url-pattern>
</filter-mapping>
</web-app>
<?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="helloworld" extends="struts-default">
<action name="hello"
class="com.tut.struts2.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ 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>
你好,世界
来自Struts2的Hello World
请输入您的姓名
我认为您在struts.xml
中的映射是错误的。在struts.xml
中,您有/HelloWorld.jsp
,框架只需将上下文路径
附加到/HelloWorld.jsp
,并使用它来定位您的HelloWorld.jsp
。但是从您发布的图像来看,HelloWorld.jsp
位于WEB-INF
目录中。这就是struts无法定位jsp的原因。在struts.xml
中重新映射jsp,或更改HelloWorld.jsp
的位置以反映当前映射。我想这会解决你的问题
编辑
将
struts2.xml
更改为struts.xml
工作不正常-详细索引页正在工作,但HTTP状态404-没有为命名空间/和操作名hello映射的操作。找不到操作或结果没有为命名空间/和操作名hello映射的操作。-webcontent文件夹中的[unknown location]helloworld jsp是否正确?它仍然不工作,没有进入action类..在该程序终止之前..@404您使用什么url访问应用程序。你能发布吗?@404试试本地主机:8080/m2r/hello。我假设m2r
是您的上下文路径。请发布完整的web.xml
,以便我检查它是否有问题。@404虽然这不是问题的原因,但能否将筛选器的url映射/hello
更改为/*
。测试我发布的url,看看它是否有效。请同时将struts2.xml
更改为struts.xml
。尝试过但没有办法。从昨天开始我一直在这样做,但仍然不知道问题出在哪里……我已经尝试了我知道的每件事
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ 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>