详解Struts2动态方法调用
动态方法就是一个Action对应多个请求,减少Action的数量
1、指定method属性
/jsp/add.jsp
2、感叹号(!)方式(不推荐使用)
/jsp/test.jsp /jsp/add.jsp /jsp/update.jsp
需要在struts.xml中加入如下常量:
调用不同方法使用:
访问execute方法:http://localhost:8080/TestStruts2/HelloWorld.action
访问update方法:http://localhost:8080/TestStruts2/HelloWorld!update.action
访问add方法http://localhost:8080/TestStruts2/HelloWorld!add.action
3、通配符方式
Action配置:
/jsp/test.jsp /jsp/add.jsp /jsp/update.jsp
访问execute方法:http://localhost:8080/TestStruts2/HelloWorld.action或http://localhost:8080/TestStruts2/HelloWorld_execute.action
访问add方法http://localhost:8080/TestStruts2/HelloWorld_add.action
注:为简化struts.xml配置,可以将action配置为:
/jsp/test.jsp /jsp/{2}.jsp /jsp/{2}.jsp
第一个*对应action,第二个*对应method
注意result标签的name属性不可以使用通配符
java类
publicclassHelloWorldActionextendsActionSupport{
@Override
publicStringexecute()throwsException{
System.out.println("executemethod");
return"success";
}
publicStringadd(){
System.err.println("addmethod");
return"add";
}
publicStringupdate(){
System.out.println("updatemethod");
return"update";
}
}
总结
以上就是本文关于详解Struts2动态方法调用的全部内容,希望对大家有所帮助。感兴趣的朋友可以参阅:struts2开发流程及详细配置 Struts2修改上传文件大小限制方法解析等,有什么问题可以随时留言,小编会尽快回复大家。
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短