虽然Struts2号称是一个全新的框架,但这仅仅是相对Struts 1而言。Struts 2 与Struts 1相比,确实有很多革命性的改进,但它并不是新发布的新框架,而是在另一个赫赫有名的框架:WebWork基 础上发展起来的。从某种程度上来讲,Struts2没有继承Struts 1的血统,而是继承WebWork的血统。或者说,WebWork衍生出了Struts2,而不是Struts 1衍生了Struts2。因为Struts2是WebWork的升级,而不是一个全新的框架,因此稳定性、性能等各方面都有很好的保证:而且吸收了 Struts 1和WebWork两者的优势,因此,是一个非常值得期待的框架。
以下通过小实例快速架构struts2:
第一步:
1、到struts2 官网下载struts2相关jar包。
2、用myeclipse新建一个web项目叫teststruts2,只需把下载的struts2 jar包解压,把 commons-logging-1.0.4.jar、ognl-2.6.11.jar、freemarker-2.3.8.jar、struts2-core-2.0.14.jar、xwork-2.0.7.jar 这5个jar包拷贝到项目中。
第二步:
在web.xml文件中注册struts2,在web.xml文件中加入如下配置信息:
第三步:
编写我们自定义的Action,代码如下:
第四步:在scr目录下新建一个struts.xml(struts2的配置文件),内容如下:
第五步:在/struts2目录下新建 index.jsp页面。
第六步:将web实例部署到tomcat中。测试:
在地址栏输入: http://localhost:8080/teststruts2/simple/test!hello.action
能显示 hello struts2 表示你的测试成功了。
以下通过小实例快速架构struts2:
第一步:
1、到struts2 官网下载struts2相关jar包。
2、用myeclipse新建一个web项目叫teststruts2,只需把下载的struts2 jar包解压,把 commons-logging-1.0.4.jar、ognl-2.6.11.jar、freemarker-2.3.8.jar、struts2-core-2.0.14.jar、xwork-2.0.7.jar 这5个jar包拷贝到项目中。
第二步:
在web.xml文件中注册struts2,在web.xml文件中加入如下配置信息:
<!-- 注册struts2 -->
<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>
第三步:
编写我们自定义的Action,代码如下:
package com.changtusoft.web.struts2.test;
// struts2 简单测试的Action
public class VerySimpleAction {
public String hello() {
// 根据返回值指向到页面
return "success";
}
}
第四步:在scr目录下新建一个struts.xml(struts2的配置文件),内容如下:
<?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">
<!-- struts2配置文件 -->
<struts>
<package name="simple" namespace="/simple" extends="struts-default">
<!-- struts2简单的例子 -->
<action
name="test"
class="com.changtusoft.web.struts2.test.VerySimpleAction"
method="hello"
>
<result name="success">/struts2/index.jsp</result>
</action>
</package>
</struts>
第五步:在/struts2目录下新建 index.jsp页面。
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>struts2简单测试例子</title>
</head>
<body>
hello struts2!
</body>
</html>
第六步:将web实例部署到tomcat中。测试:
在地址栏输入: http://localhost:8080/teststruts2/simple/test!hello.action
能显示 hello struts2 表示你的测试成功了。
2689

被折叠的 条评论
为什么被折叠?



