wangy404 2011-08-26 13:22
浏览 236
已采纳

获取地址栏参数的疑惑

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

  • 写回答

4条回答 默认 最新

  • AngelAndAngel 2011-08-26 13:27
    关注

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

    你可以试试。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料