初识Struts2_动态方法访问
一、Action
1 public class UserAction extends ActionSupport { 2 public String show(){ 3 return "show"; 4 } 5 public String add(){ 6 return "add"; 7 } 8 public String update(){ 9 return "update"; 10 } 11 public String delete(){ 12 return "delete"; 13 } 14 }
二、配置文件
1 <package name="default" namespace="/" extends="struts-default"> 2 <!-- 3 访问方式: 4 localhost:8080/Struts2_DsmMethod/userAction!add 5 localhost:8080/Struts2_DsmMethod/userAction!update 6 localhost:8080/Struts2_DsmMethod/userAction!delete 7 localhost:8080/Struts2_DsmMethod/userAction!show 8 !后面的内容,相当于动态指定 action的method属性 9 --> 10 <action name="userAction" class="cn.su.action.UserAction"> 11 <result name="add">/userAdd.jsp</result> 12 <result name="update">/userUpdate.jsp</result> 13 <result name="show">/userShow.jsp</result> 14 <result name="delete">/userDelete.jsp</result> 15 </action> 16 </package>