如何从servlet页面中的ajax请求获取数据?
如何从servlet页面中的ajax请求获取数据。这里我通过 $.ajax
调用 servlet。
var dataRequestObject= {};
dataRequestObject= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
var dataRequestHeader= {};
dataRequestHeader= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
$.ajax({
type:'POST',
url:'http://localhost:8090/SampleServlet1/serv', //calling servlet
cache:false,
header:dataRequestHeader,
data:dataRequestObject,
success:function(){ alert("Request Done");},
error:function(xhr,ajaxOptions){
alert(xhr.status + " :: " + xhr.statusText);
}
});
我需要 setvlet 页面中的这些数据和标题。
How to get the data from ajax request in servlet page. Here I'm calling the servlet by $.ajax
.
var dataRequestObject= {};
dataRequestObject= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
var dataRequestHeader= {};
dataRequestHeader= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
$.ajax({
type:'POST',
url:'http://localhost:8090/SampleServlet1/serv', //calling servlet
cache:false,
header:dataRequestHeader,
data:dataRequestObject,
success:function(){ alert("Request Done");},
error:function(xhr,ajaxOptions){
alert(xhr.status + " :: " + xhr.statusText);
}
});
I need those data and header in setvlet page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
header
选项无效。它必须是标题
。另请参阅jQuery.ajax()
文档。您可以使用
HttpServletRequest#getHeader()
。您可以使用
HttpServletRequest#getParameter()
。然而,我想知道通过标题和参数复制数据有多么有用......
First, the
header
option is invalid. It needs to beheaders
. See also thejQuery.ajax()
documentation.You can get the individual request headers by their name using
HttpServletRequest#getHeader()
.You can get the individual request parameters by their name using
HttpServletRequest#getParameter()
.I however wonder how useful it is to duplicate the data over headers and parameters...