分别使用ajax的XMLHttpRequest的open方法的"get"和"post"方式如何传递参数
在struts的action中又是如何获得参数strutsajaxopen方法传递参数action接收参数

解决方案 »

  1.   


    xmlhttp.open("GET","xxx.action?param=xxx",true);
    action中,如楼上request.getParameter()
      

  2.   

    action中我是通过request.getQueryString()接受参数的。
    js中是这样写的:
         xmlHttp.open("POST", "bybrand?NOKIA", true);
         xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
         xmlHttp.send();
    参数得到了,action中的方法也执行了,返回结果也成功了,就是不跳转页面
      

  3.   

    public String byBrand() {
    System.out.println("进入byBrand方法:");
    request = ServletActionContext.getRequest(); String brand = request.getQueryString();// 获得ajax传递的参数 System.out.println("action中的brand2:" + brand);
    qbc = new QBCDao();
    list = qbc.gainByBrand(brand);
    System.out.println("action中list的长度:" + list.size());
    if (list.size() <= 0) {
    System.out.println("input");
    return INPUT;
    } else {
    request.setAttribute("listAll", list);
    System.out.println("success");
    return SUCCESS;
    }
    }
    struts.xml中的配置
    <action name="bybrand" class="com.hsm.action.QBCAction" method="byBrand">
    <result name="success">show.jsp</result>
    <result name="input">show.jsp</result>
    </action>
    控制台已经通过传递的参数查询到数据,已打印出“success”,只是页面没有跳转