我在从动态生成的 Javascript 表单调用 servlet doPost 方法时遇到问题。
var form = document.createElement("form");
form.setAttribute("action", 'cisco-fetch-devices');
form.setAttribute("method", 'POST');
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", 'hiddeninputfield');
hiddenField.setAttribute("value", data);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
但是,我可以从 jquery ajax 调用中调用相同的 servlet ''cisco-fetch-devices':
$.post("cisco-fetch-devices", { orderId : data},
function(data) {
alert("Data Loaded: " + data);
});
JS 动态表单提交正在生成“找不到文件错误”
这是我的 doPost 方法:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/csv");
response.setHeader ("Content-Disposition", "attachment;filename=\"tableincsv.csv\"");
String orderId = request.getParameter("orderId").toString();
java.io.PrintWriter out = response.getWriter();
out.print("TEST DAta");
}
您能否让我知道 JS 的传统 POST 调用中可能存在什么问题?
谢谢,阿迪亚