0
我有一个servlet,我的目标是从进程请求中返回一个客户对象,然后可以在我的jquery中访问此对象。有谁知道我可以怎么做呢?将自定义对象从servlet传递给Jquery
e.g. myObject.getMethod()
servlet代码:
Customer loginResult;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
/* TODO output your page here. You may use following sample code. */
//request.setAttribute("customerFirstName", loginResult.getFirstName()); //String Value
//request.setAttribute("customerID", loginResult.getCustomerID()); //IntegerValue
out.println(loginResult);
} finally {
out.close();
}
}
JSP代码:
<script type="text/javascript">
$().ready(function() {
$('#submit').click(function() {
var dataf = 'email=' + $('#email').val()
+ '&password=' + $('#password').val();
$.ajax({
url: "http://localhost:8080/RetailerGui/loginServlet",
type: "get",
data: dataf,
success: function(data) {
alert(data);
}
});
return false;
});
});
</script>
是否有人可以帮助我解决这个问题,感谢您对您的帮助提前。
这不是JSP代码,这只是javascript ... – Virus721
@ Virus721抱歉删除了标签我的代码是在jsp文件中。所以我不小心选了它。 – KSM
这可能有助于http://stackoverflow.com/questions/3832792/access-request-object-in-javascript – Susie