1.下载struts开发包jar
2.导入主要的包jar
3.在src下添加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>
<action name="test" class="com.opensymphony.xwork2.ActionSupport" method="execute">
<result name="success" type="dispatcher">
<param name="location">/MyJsp.jsp</param>
</result>
</action>
</struts>
4.配置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>
5.action中通配符使用
*表示全部 {1} 表示取值(第一个*的字符)
名字有规律的情况下可以使用,但是要少有。。
6. 通痛配符中的匹配顺序
my.add.user--> my.add--> my 默认顺序在前就先匹配 跟顺序有关
7.没有指定的是服务器转发
指定type属性
redirect 浏览器重定向
redirectAction 重定向另外一个包中的action 指定param "actionName" "nameSpace"