JDK1.6+EclipseWTP1.5.3+MyEclipse5.5+Struts2.0.6+Tomcat6 Struts2 开发 第一个 HelloWord!

内容提要:本文以一个“Hello World”的简单Demo,开始struts2之旅。
开发环境: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的示例程序以及一些HTMLAPI文档。

本项目中,为简单起见,选用了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的开发吧,兄弟们
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值