<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.BufferedReader"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.io.InputStream"%>
<%@ page import="java.io.InputStreamReader"%>
<%@ page import="java.net.MalformedURLException"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLConnection"%>


<link rel="stylesheet" href="/ens/resource/css/style.css"/>

<html>
	
	<%
		String html = "";
	%>
	<%
		StringBuffer sbuf = new StringBuffer();
		try {
			 
			// URL 객체 생성
			String queryString = request.getQueryString();			
			//System.out.println(queryString);
			//URL url = new URL("http://localhost:18090/kko/mydoc/page/prnt?"+queryString);
			URL url = new URL("http://localhost:18090/api/biz/mbl/kko/mblPage?"+queryString); 
			 
			// URLConnection 생성
			URLConnection urlConn = url.openConnection();
			urlConn.setUseCaches(false);        //매요청마다 새 응답값을 얻도록 "false" 설정
			urlConn.setDefaultUseCaches(false); //캐싱데이터(useCaches) 디폴트 값 설정
			urlConn.setReadTimeout(10000);       //6초 설정(서버응답 read 시간)
			urlConn.setDoInput(true);           //서버응답을 InputStream으로 읽는 경우 true(디폴트), 아니면 false
			urlConn.setDoOutput(false);         //데이터를 OutputStream으로 출력하는 경우 true, 아니면 false(디폴트)

			try (InputStream is = urlConn.getInputStream();
				 InputStreamReader isr = new InputStreamReader(is, "UTF-8");
				 BufferedReader br = new BufferedReader(isr)) {

				String str;
				while ((str = br.readLine()) != null) {
					sbuf.append(str + "\r\n");
				}

			}
			 
			 
			// 콘솔에 출력하기
			//System.out.println(sbuf.toString()) ;
			html = sbuf.toString();
			 
		} catch (MalformedURLException e) {
			e.printStackTrace();
			html = "<script>alert('재시도 바랍니다. [ 잘못된 URL : "+ e.getMessage() +" ]')</script>";
		} catch (IOException e) {
			e.printStackTrace();
			html = "<script>alert('재시도 바랍니다. [ 연결 실패 : "+ e.getMessage() +" ]')</script>";
		}
	%>
	<%= html %>
	

</html>