상세 컨텐츠

본문 제목

ajax , json 을 이용해서 회원정보 가져오기

관리X 과거글

by 까먹기전에 2015. 3. 3. 15:37

본문

반응형

======================a.jsp===================


<%@ page language="java" contentType="text/html; charset=EUC-KR"

pageEncoding="EUC-KR"%>

<%@ page import="java.util.*"%>

<%@ page import="kr.co.seoulit.member.dao.*"%>

<%@ page import="kr.co.seoulit.member.to.*"%>             // 멤버다오 필수 

<%@ page import="net.sf.json.*"%>

<% 

MemberDAO dao=MemberDAOImpl.getInstance();

MemberBean member=dao.selectMember("ede");

HashMap<String,Object> map=new HashMap<String,Object>();

map.put("member",member);

JSONObject jsonObject= new JSONObject();

jsonObject.putAll(map);

out.println(jsonObject);

%>


======================b.jsp=========================


<%@ page language="java" contentType="text/html; charset=EUC-KR"

pageEncoding="EUC-KR"%>

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<script>

$(document).ready(function() {


$("#b").click(function() {

$.ajax({

url : "a.jsp",

dataType : "json",

cache : false,

success : function(data) {

var str = "";

str += "ID:" + data.member.id;

str += "PW:" + data.member.pw;

str += "ADDR:" + data.member.addr;

str += "TEL:" + data.member.tel;


$("#con").html(str);

}

});

});


});

</script>

<body>

<input type="button" id="b" value="회원정보보기">

<div id="con"></div>

</body>

</html>

관련글 더보기