Struts——通配符、常量

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值