404错误,第一个struts2程序.
zyr08 2013-10-23 07:42:11 我从网上完完整整抄过来的程序,但是无法运行成功,弄了好几天了。请大家帮忙看看哪里出现了问题。
struts2 教程之第一个HelloWord示例
1.把struts2开发至少所需要的六个jar包导入到lib下。
2.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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.新建一个HelloAction类
package com.club.web.action;
public class HelloAction {
private String message = "Hello,Baby !";
public String getMessage() {
return message;
}
public String execute() {
return "success";
}
}
4.在src下新建一个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>
<package name="default" namespace="/test" extends="struts-default">
<action name="hello" method="execute">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
</struts>
5.在/WEB-INF/page下新建一个hello.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>第一个struts2.1.8示例</title>
</head>
<body>
${message}@-@
</body>
</html>
6.发布该程序,url访问:http://localhost:8080/struts/test/hello.action
-------------------------------------------------------------
访问提示404错误,问题出现在哪里呢?