详解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 婆婆高寿祝福语大全简短