形如user.do?to=index这样的url
sturts2为何获取不到to的值??

解决方案 »

  1.   


    ActionContext.getContext().getParameters().get("to")你是这样获取的吗?
      

  2.   

    struts2中默认以.action为后缀。在action中,你有setTo    getTo函数吗? 有to这个字段吗
      

  3.   

    当然可以获取到,和一般的submit提交一样的获取方式,1楼兄弟给出的就可以做到
      

  4.   

    可以取到,在对应的action中需要有getTo()和setTo()方法,又或者你的getModel()返回的那个对象里有to这个属性且有相应get,set方法
      

  5.   

    我在对应的action中有 有getTo()和setTo()方法 
    但是还是获取不到 
    拓展名为.do是我设置的 没有采用默认的.action
    我的这个user.do?to=index 是 在struts.xml中 redirect过来的
    就是访问不到to的值
    高手请赐教!
      

  6.   

    导入类  import org.apache.struts2.ServletActionContext;
    String to = (String)ServletActionContext.getRequest().getParameter("to");
      

  7.   

    request.getParameter("to"); 也该这样就行了
      

  8.   

    拦截器配置了吗,楼主检查下你的strut.xml文件,有没继承default拦截器。如果没配置,肯定拿不到
      

  9.   

    给你一段代码参考下:struts2 Action中获取request, response对象的方法 :
      ActionContext ctx = ActionContext.getContext();           
      HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);        
      HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE); 
      

  10.   


    是的,struts2要转一下弯才能得到request, response对象
      

  11.   


    redirect过来的参数是得不到的.  
      

  12.   

    看看你的action最是否有get/set方法。
      

  13.   

    这样配置试试:<result name="...." type="redirect">
      <param name="location">user.do</param>
      <param name="to">index</param>
    </result>可以到这找找答案http://struts.apache.org/2.x/docs/core-developers-guide.html