0

我可以从 js 中看到参数,但我不能使用 getParameter 来获取它们。有什么问题?

js代码

var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
var req = new XMLHttpRequest(); 
req.open("POST", "../PersonTest", true);
req.onreadystatechange = function(){
    if (req.readyState == 4) {
        if (req.status == 200) {
            alert(req.responseText);
        } else {
            alert("HTTP error " + req.status + ": " + req.statusText);
        }
    }
}
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send("email=" + email + "&password=" + password);

小服务程序代码

    response.setContentType("text/xml;charset=UTF-8");  
    PrintWriter out = response.getWriter();  
    try {  
        //print request content
        ServletInputStream is = request.getInputStream();   
        ... 
        System.out.println(new String(baos.toByteArray(), "utf-8"));

        //get parameter
        String email = request.getParameter("email");  
        String password = request.getParameter("password");
        System.out.println(email + "  " + password);

    } 

servlet 输出:email=123&password=123 null null

4

0 回答 0