一、Struts2.0的创建
1),添加jar包
?? 1, commons-fileupload-1.2.1.jar
?? 2, commons-io-1.3.2.jar
?? 3, commons-logging-1.0.4.jar
?? 4, freemarker-2.3.13.jar
?? 5, ognl-2.6.11.jar
?? 6, struts2-core-2.1.6.jar
?? 7, xwork-2.1.2.jar
注:要与Spring整合,让Spring托管Struts的Action,那么需要添加Struts2.0的
???????? struts2-spring-plugin-2.1.6.jar
2),创建struts.xml,放在src目录下,并添加相应的action
? <?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>??
<include file=”struts-default.xml”/>
<package name=”com.login”? extends=”struts-default”>
?<action name=”login” method=”login”>???
?<result name=”success” type=”redirect”>success.jsp</result>
</action>???
</package>
??? </struts>
3), 在web.xml加入filter,
????????????? (注:用过滤器的原因是:要对传来的各种url进行分类,转向,即过滤。相似的还有servlet
?????????????????????? 而Spring用监听器,listen,当监听到action创建时就注入属性)
<filter>
<filter-name>struts2</filter-name>
<filter-class>
??? org.apache.struts2.dispatcher.FilterDispatcher? //默认就会读取src下的struts.xml
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
4), 做jsp即可