论坛首页 Java企业应用论坛

Struts2学习之开发环境搭建

浏览 3043 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-07-01  
1、Struts2优点
Struts2是有webwork2基础发展而来的。和Struts1相比,Struts2的优点如下:
(1)Struts2是无侵入式设计,而Struts1是侵入式设计。
(2)Struts2提供了拦截器功能,利用拦截器可以实现AOP编程,如权限拦截等功能。
(3)Struts2提供了类型转换器。
(4)Struts2提供了多种表现层技术,如jsp、freeMarker等。
(5)Struts2的输入校验可以对指定方法进行校验。
(6)Struts2提供了全局范围、包范围和Action范围的国际化资源文件实现管理。
2、Struts2开发环境搭建步骤
(1)开发一个web工程
(2)找到Struts2开发需要的jar
http://struts.apache.org/download.cgi#struts234网站下载struts-2.x.x-all.zip,目前最新的版本是2.3.4。下载完毕后,解压文件,开发struts2应用需要的jar在解压后文件的lib文件夹下,不同的应用需要的jar不一样。下面给出开发struts2程序最少需要的jar。
struts2-core-2.x.x.jar:Struts2的核心类库
xwork-2.x.x.jar:xwork类库,struts2在其上构建
freemarker-2.3.x.jar:struts2的UI标签模板使用freemarker编写
commons-logging-1.1.x.jar:ASF日志包,struts2通过这个日志包来支持jdk1.4+和log4的日志记录
ognl-2.6.x.jar:对象图导航语言,struts2通过其读写对象属性
commons-fileupload-1.2.1.jar:文件上传组件,2.1.6之后,必须加入此jar
(3)编写Struts2的配置文件struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE struts SYSTEM "http://struts.apache.org/dtds/struts-2.0.dtd" >-->
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
</struts>

(4)在web.xml中加入Struts2 MVC启动配置
<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>

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics