我正在尝试学习Struts2,但我无法创建一个正常工作的hello world应用程序。当从JSP发出请求时,它会给出404(页面未找到)错误。我将所有lib文件保存在lib文件夹中,将struts.xml
放在classes文件夹中,但我仍然收到此错误。
以下是观点:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<form action="HelloWorld">
<input type="submit">
</form>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是我的struts.xml
文件
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="HelloWorld" class="vaannila.HelloWorld">
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
</struts>
这是错误:
HTTP状态404 - / Testi / HelloWorld
输入状态报告
message / Testi / HelloWorld
描述请求的资源(/ Testi / HelloWorld)不可用。
Apache Tomcat / 6.0.33
答案 0 :(得分:3)
这与您在Struts2 : Using form action中发布的问题相同,只是更加详细。
您遇到的问题出在您使用的表单标记中。它不是struts表单标记,并且struts表单标记中的action属性在HTML标记的action属性中的处理方式不同。
我认为Struts2 : Using form action中的答案对您有用。
PS:如果您尚未更改操作扩展程序,则可以通过在标准HTML标记操作的末尾添加.action来完成此工作:
<form action="HelloWorld.action">
...
</form>
答案 1 :(得分:1)
我建议在tomcat.webapps文件夹下创建一个新文件夹,并根据标准放置所有文件,如果您使用任何IDE,请尝试一下。
尝试从头开始调试
我认为这应该是一个映射问题。
答案 2 :(得分:0)
您可以发布错误日志内容吗?关于项目的结构.404指示您的服务器能够找到所请求的资源,这可能是您的映射问题,或者可能无法在类路径中找到映射文件。 你需要在类路径中放置struts.xml文件,所以如果你使用Eclipse只需将你的struts.xml文件放在src文件夹中,那么eclipse知道如何处理这个
学习struts2的最佳方法是从官方网站下载示例应用程序
这将有助于您更好地理解和学习struts2,因为
答案 3 :(得分:0)
将导入的lib添加到Action类
前:
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
//....
//....
}