获取地址栏参数的疑惑

小弟最近在看一个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类得其他方法,请指点!!!本想自己写个方法去的地址栏参数,但是总是感觉没有研究透,放不下,这种方法确实是简单了许多啊!!!

因为private String action = "index"; 这里这样声明,那么就得用struts2的环境,这样的东西要能够取到值,你得在你的页面最好用struts2的标签。

你可以试试。

比如 ……这个里面用你的s:text什么的/s:form 这样提交。

还有 struts2的动态调用已经足够灵活了,为什么要这么调用了 ,你这个方式不可取,每次都得反射出来。你现在已经ssh2一起整合了,不要这么做啦。

楼上解释很到位