struts中的*通配符的问题

      其实用到method={数字}的时候,相应的前面的action是要出现*通配符来搭配的。比如一个小例子:
<action name="user_*" class="UserAction" method="{1}">
在对应的jsp中:
<form action="user_userLogin2" method="post">
那么struts会将user_userLogin2这个action按照user_*的格式解析,把*号对应位置的字符串取出来,放到method={}这个中括号里替代数字的位置,1就是指第一个*号位置的字符串。
这里看不出数字不同的区别,在:
<action name="*_*" class="com.xy.{1}Action" method="{2}">
中就看得明白了,你提交的action都会按格式分解,比如jsp里是User_add,那么就会变成:

class="com.xy.UserAction" method="{add}"


struts.xml中的配置:
<!-- 配置用户模块的action -->
    <action name="user_*" class="userAction" method="{1}">
        <result name="registPage">/WEB-INF/jsp/regist.jsp</result>
    </action>
/*
此时method={1}中的{1}代表user_*中的*,即加入你访问路径是/user_registPage.action,则此刻访问的是该Action中的registPage方法。同理,如果通配符* == delete,则就访问的是delete方法。
当name中含有多个通配符的时候,method={2} ,就代表第二个通配符,同理以此类推。
这种方式更灵活的简化了struts.xml的配置文件。
*/
regist.jsp页面中的代码段:
<li id="headerRegister" class="headerRegister" style="display: list-item;">
                    <a href="${ pageContext.request.contextPath }/user_registPage.action">注册</a>|
                </li>
/*
user_registPage.action对应 name="user_*",通配符*就是registPage,
method="{1}"里面的{1}就是代表registPage()方法,
这个registPage()方法存在于 UserAction中
*/
Action类:
public class UserAction extends ActionSupport{
    /**
     * 跳转到注册页面的执行方法
     */
public String registPage(){            
        return "registPage";
    }
}
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值