1.Struts2的action的开发的几种方式。
方式1:继承ActionSupport(如果使用struts的数据校验的功能,必须继承此类)
方式2:实现Action接口
方式3:不继承任何类,不实现任何接口
2.通配符:
在struts中的配置信息中,可以用*与{1}优化配置
< action name="login" class="cn.jjs.b_execute.UserAction" method="login">
< result name="login">/login.jsp< /result>
< /action>
< action name="register" class="cn.jjs.b_execute.UserAction" method="register">
< result name="register">/register.jsp< /result>
< /action>
与下面的配置作用一样
< action name="user_*" class="cn.jjs.b_execute.UserAction" method="{1}">
< result name="{1}">/{1}.jsp< /result>
< /action>
3.Struts中路径匹配原则:
< package name="config" extends="struts-default" namespace="/user">
< action name="user_*" class="cn.jjs.b_execute.UserAction" method="{1}">
< result name="{1}">/{1}.jsp< /result>
< /action>
< /package>
访问路径:http://localhost:8080/MyStruts2/user/user_login
4.Struts常量:
-
Struts中默认访问后缀:
- Struts1中默认访问后缀是:*.do
- Struts2中默认访问后缀是:*.action 如何修改默认访问后缀:
-
Struts2的 .action访问后缀在哪里定义?
- 在struts2-core.jar/org.apache.struts/default.properties
- struts.action.extension=action,
- 在struts.xml中通过常量修改:
<constant name="struts.action.extension" value="action,do,"></constant>
指定访问后缀为:action/do/没有访问后缀 都可以。
value="action,do, :访问后缀为:action/do/没有访问后缀。
value="action,do :访问后缀为:action/do。
value="action :访问后缀为:action。
5.全局跳转配置、配置各项默认值
全局视图配置:
< !--全局跳转配置-->
< global-results>
< result name="success">/index.jsp< /result>
< /global-results>
配置各项默认值:
< !--配置的各项默认值
name: 只配置了访问路径名称。
class: 默认执行的action在struts-default.xml中有配置
< default-class-ref class="com.opensymphony.xwork2.ActionSupport"/>
method: 默认为execute
默认的方法execute返回值为success,对应的页面去全局视图找
-->
< action name="test">< /action>