Struts2的环境搭建
10级学员 李捧课堂笔记
一、找到开发struts2开发应用使用的jar文件
1、 struts2-core-2.x.x.jar :Struts 2框架的核心类库
2、 xwork-2.x.x.jar :XWork类库,Struts 2在其上构建
3、 ognl-2.6.x.jar :对象图导航语言(Object Graph Navigation Language),struts2框架通过其读写对象的属性
4、 freemarker-2.3.x.jar :Struts 2的UI标签的模板使用FreeMarker编写
5、 commons-logging-1.1.x.jar :ASF出品的日志包,Struts 2框架使用这个日志包来支持Log4J和JDK 1.4+的日志记录。
6、 commons-fileupload-1.2.1.jar 文件上传组件,2.1.6版本后必须加入此文件
二、编写Struts2的配置文件。
Struts2默认的配置文件为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>
三、在web.xml中加入Struts2 MVC框架启动配置添加启动,struts2所依赖的filter过滤器在web.xml文件中,如下:
<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>