JSP 크로스 도메인간 Ajax Proxy 처리
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
| <%@ page pageEncoding="euc-kr" %> <%@ page import = "org.apache.commons.httpclient.HttpClient" %> <%@ page import = "org.apache.commons.httpclient.methods.GetMethod" %> <%@ page import = "org.apache.commons.httpclient.HttpStatus" %> <% request.setCharacterEncoding("utf-8"); String url = "http://openapi.naver.com/search"; String queryString = request.getQueryString(); HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setQueryString(queryString); try { int statusCode = client.executeMethod(method); out.clearBuffer(); response.reset(); response.setStatus(statusCode); if (statusCode == HttpStatus.SC_OK) { String result = method.getResponseBodyAsString(); response.setContentType("text/xml; charset=utf-8"); out.println(result); } } finally { if (method != null) method.releaseConnection(); } %>
|