struts2.5感叹号和通配符实现动态方法

很多人对struts2中的使用不了解,经过研究,特备案

网页中的书写方式
 <body>
<!-- workA:常用的直接调用execute 方法,默认的方法 -->
<form action="test.action" method="post">
<input type="text" id="name" name="name"/>
execute
<input type="submit"/>
</form>
<!-- workB:直接使用 method来进行 非 execute方法的调用 -->
<form action="testA.action" method="post">
<input type="text" id="name" name="name"/>
调用其他方法OK
<input type="submit"/>
</form>
<!-- workC:和testB用于!连接的例子  -->
<form action="testB!update.action" method="post">
<input type="text" id="name" name="name"/>
调用其他方法update 
<input type="submit"/>
</form>
<!-- workD:通配符的使用* 但是通配符会加大系统的负担,所以一般情况下不建议使用  -->
<form action="test_add.action" method="post">
<input type="text" id="name" name="name"/>
通配符
<input type="submit"/>
</form>
</body>

配置文件中的书写方式。

  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 和testB一起用于 ! 进行非 execute 方法的调用  用于开启!的使用-->
<package name="default" extends="struts-default" namespace="/" strict-method-invocation="false">
<!--strict-method-invocation用于 * 通配符的使用,开启统配符号 -->
<!-- workA:常用的直接调用execute 方法,默认的方法   -->
<action name="test" class="com.action.LoginAction">
<result name="scrount">index.jsp</result>
</action>
<!-- workB:直接使用 method来进行 非 execute方法的调用 -->
<action name="testA" class="com.action.LoginAction" method="delete">
<result name="scrount">index.jsp</result>
</action>
<!-- workC:和testB用于!连接的例子 -->
<action name="testB" class="com.action.LoginAction">
<result name="scrount">index.jsp</result>
</action>
<!-- workD:通配符的使用* 但是通配符会加大系统的负担,所以一般情况下不建议使用 -->
<action name="test_*" class="com.action.LoginAction" method="{1}">
<result name="scrount">index.jsp</result>
</action>
</package>
</struts> 

LoginAction中的方法的书写方式:
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("ex");
return "scrount";
}
public String  delete() throws Exception{
System.out.println("delete");
return "scrount";
}
public String  add() throws Exception{
System.out.println("add");
return "scrount";
}
public String  update() throws Exception{
System.out.println("update");
return "scrount";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值