开发环境:JDK1.6+EclipseWTP1.5.3+MyEclipse5.5+Struts2.0.6+Tomcat6(Tomcat5.5.20)
一. 下载 struts 2.0.6
http://struts.apache.org/downloads.html,下载struts- 2.0.6 all.zip,这个压缩包中包含了开发struts2所需的struts2-core.jar核心包以及其它struts2所依赖的JAR文件,另外还有一些struts2的示例程序以及一些HTML的API文档。
本项目中,为简单起见,选用了struts-2.0.6-all/struts-2.0.6/apps/struts2-blank-2.0.6/WEB-INF/lib中的5个jar文件(注意:不需要包含struts2-all-2.0.1.jar,另外需要commons-logging-1.1.jar)。
新建一个Web Project
项目文件:
1. Action类
/**
*
* Zhou JianGuo (小白)
* MSN:zhoujianguo_leo@hotmail.com
* 中国电信上海技术研究院 May 7, 2007
* http://www.sttri.com.cn/
*
*/
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
/**
* @author Lucifer
*
*/
public class HelloWorld extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
public HelloWorld() {
// TODO Auto-generated constructor stub
}
public static final String MESSAGE = "Struts is up and running ...";
public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}
private String message;
public void setMessage(String message){
this.message = message;
}
public String getMessage() {
return message;
}
}
2.HelloWorld.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h2><s:property value="message" /></h2>
</body>
</html>
3.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">
<display-name>Struts Blank</display-name>
<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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
4.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="tutorial" extends="struts-default">
<action name="HelloWorld" class="tutorial.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
5.struts.properties
struts.devMode = true
struts.enable.DynamicMethodInvocation = false
6.struts.xml注意要放在classes目录下
7.执行URL;http://localhost:8080/Struts2_DEMO/HelloWorld.action
8.以上测试在jdk1.5,jdk1.6,tomcat5.5.20,tomcat6下都测试通过
9.期待Hibernate3.2的开发和Spring2的开发吧,兄弟们