상세 컨텐츠

본문 제목

jsp 회원 리스트를 JSONObject , array로 받아오기

관리X 과거글

by 까먹기전에 2015. 3. 24. 11:13

본문

반응형

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

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

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<script type="text/javascript" src="jquery-2.1.3.js"></script>

<script type="text/javascript">

$(document).ready(function(){

var str='{"list":[{"id":"aa","pw":"bb","addr":"cc","tel":"dd"},{"id":"bb","pw":"bb","addr":"cc","tel":"dd"}]}';


$.ajax({

url :"b.jsp",

data:{"aa" : str},

cache:false,

success : function(data){

alert(data)

}

})


})

</script>

</body>

</html>

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

<%@page import="kr.co.seoulit.member.to.MemberBean"%>

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

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

pageEncoding="EUC-KR"%>

<%  

String str=request.getParameter("aa");

JSONObject jsonObject=JSONObject.fromObject(str); //리턴 오브젝트

JSONArray array = jsonObject.getJSONArray("list");

for(Object obj : array){

JSONObject json = (JSONObject)obj;

MemberBean member = (MemberBean)jsonObject.toBean(json,MemberBean.class);

out.write(member.getId()+member.getPw()+"//");

}

%>






관련글 더보기