小弟最近在看一个S2SH的项目,Struts的后缀改了,然后每个连接后面都带有一个action=xx的参数,有个BaseAction类:
public class BaseAction extends ActionSupport { private String action = "index"; public String getAction() { return action; } public void setAction(String action) { this.action = action; } protected String executeMethod(String method) throws Exception { Class[] c = null; Method m = this.getClass().getMethod(method, c); Object[] o = null; String result = (String) m.invoke(this, o); return result; } public String execute() { try { return this.executeMethod(this.getAction()); } catch (Exception e) { logger.error(e); return ERROR; } } }
然后其他action类继承自此类,贴一个:
public class Read extends BaseAction{ public String execute() { if (this.getAction().equalsIgnoreCase("topic")) { return this.topic(); } else if (this.getAction().equalsIgnoreCase("history")) { return this.history(); } else if (this.getAction().equalsIgnoreCase("own")) { return this.own(); } else if (this.getAction().equalsIgnoreCase("summary")) { return this.summary(); } else if (this.getAction().equalsIgnoreCase("showip")) { return this.showip(); } else if (this.getAction().equalsIgnoreCase("summaryhistory")) { return this.summaryhistory(); } else if (this.getAction().equalsIgnoreCase("showiphistory")) { return this.showiphistory(); } else if (this.getAction().equalsIgnoreCase("showupfile")) { return this.showupfile(); } else if (this.getAction().equalsIgnoreCase("attach")) { return this.attach(); } else if (this.getAction().equalsIgnoreCase("showvote")) { return this.showvote(); } else if (this.getAction().equalsIgnoreCase("waste")) { return this.waste(); } else if (this.getAction().equalsIgnoreCase("auditing")) { return this.auditing(); } else if (this.getAction().equalsIgnoreCase("auditingAttach")) { return this.auditingAttach(); } else if (this.getAction().equalsIgnoreCase("elite")) { return this.elite(); } else { return ERROR; } } }
它就一句getAction()就可以拿到url的action参数的值,但是小弟照猫画虎却死活只是action="index";所以无法执行action类得其他方法,请指点!!!本想自己写个方法去的地址栏参数,但是总是感觉没有研究透,放不下,这种方法确实是简单了许多啊!!!