Struts2开发环境搭建
1、下载Struts2开发包
http://struts.apache.org
2、开发包目录结构
3、搭建开发环境
3.1、拷贝必要jar包到classpath中
3.2、建立Struts2的配置文件
at the top of classpath(在最顶层的构建路径),建立一个默认名称为struts.xml的配置文件。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
</struts>
注意:
1.文件名大小写。
2.创建位置。
3.该名称允许修改,但是我们一般不改。
3.3、配置控制器
a、配置位置:在web.xml中
b、配置什么: struts2已经写好了的一个过滤器。
结论:struts2比struts1优秀的一个体现就是,它用了更为强大的过滤器作为控制器了。
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<display-name>struts</display-name>
<filter>
<filter-name>struts-filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
3.4、验证是否成功
部署应用,启动Tomcat,不报错表示搭建成功
over~~~
还没有评论,来说两句吧...