Struts2学习笔记之Maven构建Struts2项目(二)
Struts所需Jar包
<properties>
<java.version>1.7</java.version>
<struts2-version>2.1.8</struts2-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
Struts2的配置文件
Struts2框架启动时,默认加载在src目录下的struts.xml配置文件,所有我们需要准备struts的配置文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.8.dtd"> <struts> </struts>
启用Struts
上面我们把struts2依赖的jar包添加上了,并且有struts的配置文件,下面就是让Struts2启用
Struts需要在项目部署上服务器的时候就启动,那么我们需要如下配置:
<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>
下面就需要我们开始Struts2的编程之旅了!