Java请求servlet与空params

时间:2017-02-09 08:33:36

标签: javascript java servlets request xmlhttprequest

我确实请求使用XMLHttpRequest到Java服务器但请求params丢失。

所以这里的js代码运行正常(至少我看到它在网络标签中发送了params):

var data = JSON.stringify({
                dis: 'inline',
                ps: this.model.get('name')
            });

            var req = new XMLHttpRequest();
            req.open('POST', 'http://example.com/downloadPDF', true);
            req.responseType = 'arraybuffer';
            req.setRequestHeader("Content-type", "application/json; charset=utf-8");
            req.setRequestHeader("Content-length", data.length);

            req.onload = function (e) {
                //...
            };

            req.send(data);

我在服务器上收到没有params的请求。如果设置断点,控制器将在此处成功停止。

@RequestMapping(value = "downloadPDF", method = RequestMethod.POST, produces = "application/pdf")
    public void downloadPDF(HttpServletRequest request, HttpServletResponse response){
        String url = service + "/downloadPDF";
        log.debug(request.getParameterNames().size()) // size == 0
        List<NameValuePair> urlParameters = super.getParametersFromRequest(request);
        String browserType = request.getHeader("User-Agent");
        urlParameters.add(new BasicNameValuePair("browserType", browserType));
        super.readResponse(url, urlParameters, response);
    }

我还在doChain()之前的过滤器中捕获了请求,其参数也是空的。

0 个答案:

没有答案