我想在 javascript 调用下面进行此操作以从 GET 更改为 POST
function redirect() {
if (window.focus)
self.focus();
this.location = "/test/DownloadReport?
<%=ESAPI.encoder().encodeForJavaScript(request.getQueryString())%>";
}
所以,我在下面做了 -
function redirect() {
if(window.focus)
self.focus();
loc = '/test/DownloadReport';
var form = document.createElement("form");
var input = document.createElement("input");
input.setAttribute("value", "
<%=ESAPI.encoder().encodeForJavaScript(request.getQueryString())%>");
form.appendChild(input);
form.setAttribute("method", "post");
form.setAttribute("action", loc);
document.body.appendChild(form);
form.submit();
}
但我面临的问题是,当这段代码被执行时,servlet 会抛出错误,因为request.getQueryString()
它不正确。我怀疑我设置值的request.getQueryString()
方式不正确。你能告诉我这里需要做什么吗?