webplus_ipaddr 가이드
이 화면은 webplus_ipaddr 함수에 대한 예시화면이다.
webplus_ipaddr 함수는 로컬 PC의 IP 주소를 구하는 기능을 수행한다.
예시
샘플 JSP 정보
툴 설치 디렉토리\template\HTML5\UTIL\WEBPLUS\webplus_ipaddr.jsp.txt → webplus_ipaddr.jsp로 이름 변경후 활용한다.
템플릿 위치: /HTML5/UTIL/WEBPLUS/webplus_ipaddr
템플릿 파일
화면 스크립트
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
function btn_wplusipaddr_on_mouseup(objInst) { var ipaddr_info; ipaddr_info = this .webplus_ipaddr(); factory.consoleprint(factory.jsonstringify(ipaddr_info)); this .fld_result.settext(ipaddr_info.result); this .fld_errcode.settext(ipaddr_info.err_code); this .fld_errmsg.settext(ipaddr_info.err_msg); this .fld_ipaddr.settext(ipaddr_info.ip_addr); } /** * webplus_ipaddr.jsp 파일을 연계하여 서버에 있는 파일 크기 및 수정시각 정보를 구함 * @returns {*} IP 정보 오브젝트 (아래 ipaddr_info 변수 주석 참조) */ function webplus_ipaddr() { var ipaddr_info, json_str, webplus_ipaddr_url; // 파일 정보 오브젝트 ipaddr_info = { result: 0, // 처리결과값 (1: 성공, 0: 실패) err_code: 0, // 에러 코드 err_msg: "" , // 에러 메세지 ip_addr: "" // IP 주소 }; // URL 정보 설정 webplus_ipaddr_url = "http://127.0.0.1:8080/xframe5/template/HTML5/UTIL/WEBPLUS/webplus_ipaddr.jsp" ; // AJAX GET Sync 방식으로 호출 $.ajax({ url: webplus_ipaddr_url, // url method: "GET" , // 'POST', 'GET', 'PUT' async: false , // sync 방식으로 동작 (true/false) dataType: "text" , // 'xml', 'html', 'script', 'json', 'jsonp', 'text' cache: false , crossDomain: true , // withCredentials를 사용할 경우, // 서버에서도 Access-Control-Allow-Credentails를 true로 설정해야 하고, // Access-Control-Allow-Origin을 "*"로 사용할 수 없음 xhrFields: { withCredentials: true }, // 오류 발생시 error: function (jqXHR, textStatus, errorThrown) { file_info.result = 0; file_info.err_code = jqXHR.status; file_info.err_msg = "(" + jqXHR.readyState + ") " + errorThrown; }, // 성공시 success: function (data, textStatus, jqXHR) { // 수신 데이터 트림 처리 및 데이터 형식 확인 json_str = factory.stringtrim(data); if (json_str.charAt(0) != "{" ) { file_info.result = 0; file_info.err_code = 3; file_info.err_msg = "invalid data format" ; } else { ipaddr_info = factory.jsonparse(json_str) } } }); return ipaddr_info; } |
webplus_ipaddr.jsp 스크립트
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 33 34 35 36 37 38 39 |
<%@ page contentType= "text/html; charset=utf-8" %> <% // Set CORS HTTP Header Start response.setHeader( "Access-Control-Allow-Credentials" , "true" ); response.setHeader( "Access-Control-Allow-Headers" , "X-Requested-With" ); // a String containing the value of the requested header, or null if the request does not have a header of that name String origin = request.getHeader( "Origin" ); System.out.println( "request origin = " + origin); if (origin == null ) { response.setHeader( "Access-Control-Allow-Origin" , "*" ); } else { response.setHeader( "Access-Control-Allow-Origin" , origin); } // Set CORS HTTP Header End //x-forwarded-for는 클라이언트가 프록시 (Proxy) 뒤에 있을 경우 실제 IP 주소를 알기 위한 용도로 사용할 수 있다. String ip = request.getHeader( "X-FORWARDED-FOR" ); System.out.println( "X-FORWARDED-FOR = [" + ip + "]" ); if (ip == null || ip.length() == 0) { ip = request.getHeader( "Proxy-Client-IP" ); System.out.println( "Proxy-Client-IP = [" + ip + "]" ); } if (ip == null || ip.length() == 0) { ip = request.getHeader( "WL-Proxy-Client-IP" ); // 웹로직 System.out.println( "WL-Proxy-Client-IP = [" + ip + "]" ); } if (ip == null || ip.length() == 0) { ip = request.getRemoteAddr() ; System.out.println( "getRemoteAddr = [" + ip + "]" ); } out.println( "{" ); out.println( "\"result\" : \"" + "1" + "\"," ); out.println( "\"err_code\" : \"" + "" + "\"," ); out.println( "\"err_msg\" : \"" + "" + "\"," ); out.println( "\"ip_addr\" : \"" + ip + "\"" ); out.println( "}" ); %> |