서블릿을 가지고있다. 나의 목표는 jquery에서이 객체에 접근 할 수있는 프로세스 요청에서 고객 객체를 반환하는 것이다. 아무도 내가이 일을 어떻게 할 수 있는지 알고 있니?서블릿에서 Jquery로 커스텀 객체 전달하기
e.g. myObject.getMethod()
서블릿 코드 :
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 코드가 아닙니다. 이것은 단지 자바 스크립트입니다 ... – Virus721
@ Virus721 죄송합니다. 내 코드가 jsp 파일에 있습니다. 따라서 나는 우연히 그것을 선택했다. – KSM
도움이 될 수 있습니다. http://stackoverflow.com/questions/3832792/access-request-object-in-javascript – Susie