webplus_httphead 가이드
이 화면은 webplus_httphead 함수에 대한 예시화면이다.
WEB 서버에 HTTP HEAD 명령이 보안상의 이유로 제한된 경우에 활용한다.
예시
샘플 JSP 정보
툴 설치 디렉토리\template\HTML5\UTIL\WEBPLUS\webplus_httphead.jsp.txt → webplus_httphead.jsp로 이름 변경후 활용한다.
템플릿 위치: /HTML5/UTIL/WEBPLUS/webplus_httphead
템플릿 파일
화면 스크립트
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 74 75 76 77 78 79 80 81 82 83 84 85 86 |
function btn_wplushttphead_on_mouseup(objInst) { var file_info; file_info = this .webplus_httphead( "screen" , this .fld_url.gettext()); factory.consoleprint(factory.jsonstringify(file_info)); this .fld_result.settext(file_info.result); this .fld_errcode.settext(file_info.err_code); this .fld_errmsg.settext(file_info.err_msg); this .fld_filetype.settext(file_info.file_type); this .fld_fileurl.settext(file_info.file_url); this .fld_filesize.settext(file_info.file_size); this .fld_gmttime.settext(file_info.gmt_time); this .fld_localtime.settext(file_info.local_time); } /** * webplus_httphead.jsp 파일을 연계하여 서버에 있는 파일 크기 및 수정시각 정보를 구함 * @param file_type 파일 유형 ("screen"/"picklist") * @param xframe_file_url xFrame5 파일 URL ("/BIZ/biz_screen") * @returns {*} 파일 정보 오브젝트 (아래 file_info 변수 주석 참조) */ function webplus_httphead(file_type, xframe_file_url) { var file_info, file_url, json_str, webplus_httphead_url; // 파일 정보 오브젝트 file_info = { result: 0, // 처리결과값 (1: 성공, 0: 실패) err_code: 0, // 에러 코드 (1: 유효하지 않는 파라미터값, 2: 파일 없는 경우, 3: 유효하지 않은 데이터, 9: 오류 발생) err_msg: "" , // 에러 메세지 file_type: "" , // 파일 유형 ("screen"/"picklist") file_url: "" , // 파일 URL file_size: 0, // 파일 바이트 크기 gmt_time: "" , // GMT 기준 파일 수정 시각 (YYYYMMDDHHMMSS) local_time: "" // 로컬 시간대 기준 파일 수정 시각 (YYYYMMDDHHMMSS) }; // URL 정보 설정 webplus_httphead_url = "http://127.0.0.1:8080/xframe5/template/HTML5/UTIL/WEBPLUS/webplus_httphead.jsp" ; // 파라미터 정보 설정 file_url = webplus_httphead_url + "?type=" + file_type + "&url=" + encodeURIComponent(xframe_file_url); // AJAX GET Sync 방식으로 호출 $.ajax({ url: file_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 { file_info = factory.jsonparse(json_str) } } }); return file_info; } |
webplus_httphead.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 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
<%@ page contentType= "text/html; charset=utf-8" %> <%@ page import = "java.util.*" %> <%@ page import = "java.io.*" %> <%@ page import = "java.text.SimpleDateFormat" %> <% /** * factory.wplushttphead API를 통해서 호출되는 웹 서비스 모듈 * Test URL: http://127.0.0.1:8080/xframe5/template/HTML5/UTIL/WEBPLUS/webplus_httphead.jsp?type=screen&url=/1.xml * * @param type url에 대한 파일 구분 ("screen"/"picklist") * @param url xFrame5에서 사용하는 파일 URL 정보 ("/" 부터 시작, 예시: /BIZ/007190.xml) * @returns {string} Format : FileByteSize^FileLastModifyGMTDateTime^FileLastModifyLocalDateTime * -1 : file not exist * -2 : error * -3 : invalid paramter * n : file byte size */ out.clearBuffer(); String fileType = "" ; // screen/picklist String fileUrl = "" ; try { System.out.println( "webplus_httphead> start ===============================================" ); // 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 fileType = request.getParameter( "type" ); // screen/picklist fileUrl = request.getParameter( "url" ); System.out.println( "webplus_httphead> fileType = [" + fileType + "], fileUrl = [" + fileUrl + "]" ); if (fileType == null || fileUrl == null ) { out.println( "{" ); out.println( "\"result\" : \"" + "0" + "\"," ); out.println( "\"err_code\" : \"" + "1" + "\"," ); out.println( "\"err_msg\" : \"" + "invalid parameter value" + "\"," ); out.println( "\"file_type\" : \"" + fileType + "\"," ); out.println( "\"file_url\" : \"" + fileUrl + "\"," ); out.println( "\"file_size\" : \"" + "0" + "\"," ); out.println( "\"gmt_time\" : \"" + "" + "\"," ); out.println( "\"local_time\" : \"" + "" + "\"" ); out.println( "}" ); return ; } // TODO: 프로젝트 환경에서 변경해야 함. String fileAbsolutePath = "D:\\SOFTBASE\\HTML\\xframe5\\project\\terminal\\" ; fileAbsolutePath += fileType + fileUrl; System.out.println( "webplus_httphead> fileAbsolutePath = [" + fileAbsolutePath + "]" ); File file = new File(fileAbsolutePath); if (file.exists() == false ) { out.println( "{" ); out.println( "\"result\" : \"" + "0" + "\"," ); out.println( "\"err_code\" : \"" + "2" + "\"," ); out.println( "\"err_msg\" : \"" + "file not exist" + "\"," ); out.println( "\"file_type\" : \"" + fileType + "\"," ); out.println( "\"file_url\" : \"" + fileUrl + "\"," ); out.println( "\"file_size\" : \"" + "0" + "\"," ); out.println( "\"gmt_time\" : \"" + "" + "\"," ); out.println( "\"local_time\" : \"" + "" + "\"" ); out.println( "}" ); } else { long fileSize = file.length(); // A long value representing the time the file was last modified, measured in milliseconds // since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs long lLocalDateTime = file.lastModified(); Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern( "yyyyMMddHHmmss" ); // lFileModifyDateTime: the new time in UTC milliseconds from the epoch. calendar.setTimeInMillis(lLocalDateTime); String fileLocaDateTime = format.format(calendar.getTime()); // Local Time -> GMT Time TimeZone timeZone = TimeZone.getDefault(); int offset = timeZone.getOffset(lLocalDateTime); // The offset includes daylight savings time long lUTCDateTime = lLocalDateTime - offset; calendar.setTimeInMillis(lUTCDateTime); String fileGmtDateTime = format.format(calendar.getTime()); System.out.println( "webplus_httphead> Size = " + fileSize + ", GMT = " + fileGmtDateTime + ", Local = " + fileLocaDateTime); out.println( "{" ); out.println( "\"result\" : \"" + "1" + "\"," ); out.println( "\"err_code\" : \"" + "0" + "\"," ); out.println( "\"err_msg\" : \"" + "" + "\"," ); out.println( "\"file_type\" : \"" + fileType + "\"," ); out.println( "\"file_url\" : \"" + fileUrl + "\"," ); out.println( "\"file_size\" : \"" + fileSize + "\"," ); out.println( "\"gmt_time\" : \"" + fileGmtDateTime + "\"," ); out.println( "\"local_time\" : \"" + fileLocaDateTime + "\"" ); out.println( "}" ); } System.out.println( "webplus_httphead> success end ===============================================" ); } catch (Exception e) { System.out.println( "webplus_httphead> " + e.getMessage()); e.printStackTrace(); out.println( "{" ); out.println( "\"result\" : \"" + "0" + "\"," ); out.println( "\"err_code\" : \"" + "9" + "\"," ); out.println( "\"err_msg\" : \"" + e.getMessage() + "\"," ); out.println( "\"file_type\" : \"" + fileType + "\"," ); out.println( "\"file_url\" : \"" + fileUrl + "\"," ); out.println( "\"file_size\" : \"" + "0" + "\"," ); out.println( "\"gmt_time\" : \"" + "" + "\"," ); out.println( "\"local_time\" : \"" + "" + "\"" ); out.println( "}" ); System.out.println( "webplus_httphead> error end ===============================================" ); } %> |