JSP는 작업에 대해 wrong tool입니다. 템플릿 텍스트로 출력이 손상됩니다. 서블릿으로 교체하십시오. 평범한 Java IO 방법으로 URLConnection#getInputStream()
에서 HttpServletResponse#getOutputStream()
으로 스트리밍하면됩니다.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
URLConnection connection = new URL("http://other.service.com").openConnection();
// Set necessary connection headers, parameters, etc here.
InputStream input = connection.getInputStream();
OutputStream output = response.getOutputStream();
// Set necessary response headers (content type, character encoding, etc) here.
byte[] buffer = new byte[10240];
for (int length = 0; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
}
그게 전부입니다. 이 서블릿을 특정 url-pattern
에 web.xml
에 매핑하고 아약스 물건을 서블릿 URL이라고 부릅니다.
HTML, xml 또는 json을 반환 하시겠습니까? json 또는 xml이면 jsp를 사용하지 마십시오! 이를위한 서블릿이 있습니다. html 인 경우 대신 json을 사용하십시오. = P – BGerrissen
JSON 반환. – srv