第一章 介绍struts2及struts2开发环境的搭建

来源:互联网 发布:软件工程硕士 在职 编辑:程序博客网 时间:2024/06/11 01:56

struts2简介:

1.struts2低侵入式设计,struts1侵入式设计

2.struts2提供拦截器,利用拦截器进行AOP编程,实现权限拦截等功能。

3.struts2实现类型转换器,可以把特殊请求参数转换成需要的类型。

struts1则需要在底层实现BeanUtil注册类型转换器。

4.struts2提供支持多种表现层技术,如JSP、freeMarker、Velocity等

5.struts2输入校验可以对指定方法进行校验。

6.sturts2提供全局范围、包范围、Action范围的国际化资源文件管理。


struts2开发环境搭建:

1.找到struts2应用所需要的jar文件

2.编写struts2配置文件

3.web.xml中加入struts2 MVC框架启动配置


1.新建web project项目名为struts2,下载sturts-2.x.x-all.zip,

struts2所依赖的jar文件在解压目录的lib文件夹下,将文件拷贝到项目WebRoot/WEB-INF/lib目录下,struts2程序最少需要的jar文件

WebRoot/WEB-INF/lib

----struts2-core-2.x.x.jar

----xwork-2.x.x.jar

----ognl-2.6.x.jar

----freemarker-2.3.x.ja

----commons-logging-1.1.x.ja

----commons-fileupload-1.2.1.jar


2.

struts2配置文件,可以从例子中拷贝,也可以由MyEclipse自动生成

WEB-INF/classes

----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></struts>



3.web.xml配置,可以从例子中拷贝,也可以由MyEclipse自动生成

WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.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步以后,将项目放入tomcat,启动tomcat,浏览器中http://localhost:8080/struts2/index.jsp访问页面



原创粉丝点击