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