struts2 通过通配符的使用可以大大简化其配置文件。其在配置文件中的使用形式如下:
[b]一、调用相同Action中的不同方法:[/b]
[b]表达式{1}的值为 name属性值中的第一个*的值。[/b]
eg: 如果用户请求的URL为 loginAction.action 则调用Test.LoginRegistAction 中的 login 方法;
如果用户请求的URL为registAction.action 则调用Test.LoginRegistAction 中的 regist 方法;
[b]二、调用不同action的execute方法[/b]
[b]由于上面没有 method 属性 所以调用execute方法;[/b]
eg: 如果用户请求的URL为 LoginAction.action 则调用Test.LoginAction 中的 execute方法;
如果用户请求的URL为RegistAction.action 则调用Test.RegistAction 中的 execute方法;
[b]三、动态结果[/b]
当处理结果为 input时 转到 login.jsp;
当处理结果为 success时 转到 success.jsp;
当处理结果为 error时 转到 error.jsp;
method属性中的通配符同上。
转自 :
[url]http://wenku.baidu.com/view/067186778e9951e79b892706.html[/url]
[b]一、调用相同Action中的不同方法:[/b]
<action name="*Action" class="Test.LoginRegistAction" method="{1}" >
<result name="input"> /login.jsp </result>
<result name="success"> /welcome.jsp </result>
<result name="error"> /error.jsp </result>
</action>
[b]表达式{1}的值为 name属性值中的第一个*的值。[/b]
eg: 如果用户请求的URL为 loginAction.action 则调用Test.LoginRegistAction 中的 login 方法;
如果用户请求的URL为registAction.action 则调用Test.LoginRegistAction 中的 regist 方法;
[b]二、调用不同action的execute方法[/b]
<action name="*Action" class="Test.{1}Action" >
<result name="input"> /login.jsp </result>
<result name="success"> /welcome.jsp </result>
<result name="error"> /error.jsp </result>
</action>
[b]由于上面没有 method 属性 所以调用execute方法;[/b]
eg: 如果用户请求的URL为 LoginAction.action 则调用Test.LoginAction 中的 execute方法;
如果用户请求的URL为RegistAction.action 则调用Test.RegistAction 中的 execute方法;
[b]三、动态结果[/b]
<action name="*Action" class="Test.LoginRegistAction" method="{1}" >
<result name="input"> /login.jsp </result>
<result > /{1}.jsp </result>
</action>
当处理结果为 input时 转到 login.jsp;
当处理结果为 success时 转到 success.jsp;
当处理结果为 error时 转到 error.jsp;
method属性中的通配符同上。
转自 :
[url]http://wenku.baidu.com/view/067186778e9951e79b892706.html[/url]