JAVA
주소 API ( juso.go.kr ) 팝업 사용...
KIMSG
2017. 7. 21. 14:23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /* 주소검색 API */ $.ajax({ url:"http://www.juso.go.kr/addrlink/addrLinkApiJsonp.do" ,type:"post" ,data:$("#form").serialize() // 요청변수설정 ,dataType:"jsonp" // 크로스도메인으로인한jsonp이용 ,crossDomain:true ,success:function(jsonStr){ // jsonStr: 주소검색결과JSON 데이터 $("#list").html(""); varerrCode= jsonStr.results.common.errorCode; varerrDesc= jsonStr.results.common.errorMessage; if(errCode!= "0"){ alert(errCode+"="+errDesc); }else{ if(jsonStr!= null){ makeListJson(jsonStr); // JSON 데이터HTML 형태로저장 } } } ,error: function(xhr,status, error){ alert("에러발생");// AJAX 호출에러 } }); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* 주소 입력 API */ function goPopup() { var pop = window.open("<c:url value='/sample/jusoPopup.do'/>", "pop", "width=570,height=420, scrollbars=yes"); //경로는 시스템에 맞게 수정하여 사용 } function jusoCallBack(roadAddrPart1, addrDetail, zipNo){ // 도로명주소검색팝업창에서 결과를 리턴하는 스크립트로 빨간 라인은 해당 시스템에 맞게 수정하여 사용 document.getElementById('roadAddrPart1').value = roadAddrPart1; document.getElementById('addrDetail').value = addrDetail; document.getElementById('zipNo').value = zipNo; } | cs |
하고....
팝업 jsp 소스
를 해야합니다.
이 부분을 직접 구현하기... url:"http://www.juso.go.kr/addrlink/addrLinkApiJsonp.do"
이러한 컨트롤러를 작성해서
url:"/sample/getAddrApi.do" // apiSampleJSONCotroller호출
이렇게 수정을 할 수도 있습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | @RequestMapping(value="/sample/getAddrApi.do") public void getAddrApi(HttpServletRequest req, HttpServletResponse response) throws Exception{ // 요청변수설정 String currentPage= req.getParameter("currentPage"); String countPerPage= req.getParameter("countPerPage"); String resultType= req.getParameter("resultType"); String confmKey= req.getParameter("confmKey"); String keyword = req.getParameter("keyword2"); // API 호출URL 정보설정 String apiUrl= "http://www.juso.go.kr/addrlink/addrLinkApi.do?currentPage="+currentPage+ "&countPerPage="+countPerPage+ "&keyword="+URLEncoder.encode(keyword,"UTF-8")+ "&confmKey="+confmKey+"&resultType="+resultType; URL url = new URL(apiUrl); BufferedReader br = new BufferedReader(new InputStreamReader( url.openStream(),"UTF-8")); StringBuffer sb = new StringBuffer(); String tempStr = null; while(true){ tempStr = br.readLine(); if(tempStr == null) break; sb.append(tempStr); // 응답결과XML 저장 } br.close(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml"); response.getWriter().write(sb.toString()); // 응답결과반환 } | cs |
1 | <div class="btn-pack gray" onClick="goPopup(); return false;" >검색</div> | cs |
를 사용해서 검색 팝업창을 띄우고 값을 붙여넣으면 됩니다.
document.getElementById('roadAddrPart1').value = roadAddrPart1; 에 맞게 아이디 값을 주면 되죠...