나는 pdf를 생성하는 웹 서비스가있다. 내 GAE 응용 프로그램에서 나는 버튼을 가지고 있는데, 클릭 할 때 아약스의 기능을 사용한다.ajax 응답을 pdf로 표시하는 방법은 무엇입니까?
방화범으로@RequestMapping(method = RequestMethod.GET, value = PROVAWS_URL)
public void prova(HttpServletRequest httpRequest, HttpServletResponse httpResponse, HttpSession httpSession) throws IOException{
try {
URL url = new URL("http://XXXXX/sap/bc/zcl_getpdf/vbeln/yyyyyy");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization","Basic " + Base64.encodeBase64String(("username:password").getBytes()));
connection.setConnectTimeout(60000);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
// OK
ByteArrayOutputStream bais = new ByteArrayOutputStream();
InputStream is = null;
try {
is = connection.getInputStream();
byte[] byteChunk = new byte[4096];
int n;
while ((n = is.read(byteChunk)) > 0) {
bais.write(byteChunk, 0, n);
}
}
catch (IOException e) {
}
finally {
if (is != null) { is.close(); }
}
httpResponse.setContentType("application/pdf");
httpResponse.setHeader("content-disposition","attachment; filename=yyyyy.pdf");
httpResponse.getOutputStream().write(bais.toString().getBytes("UTF-8"));
httpResponse.getOutputStream().flush();
}
....
}
내가 repsonse를 참조하십시오 :
$('#test').click(function(){
$.ajax({
url: 'provaws.do',
type: 'get',
dataType: 'html',
success : function(data) {
}
});
});
이
는 URL을 가져올 수를 사용하여, 통화 WS있어 자바의 방법 난에 아약스의 기능 설정이 필요가있는 무엇%PDF-1.3
%âãÏÓ
2 0 obj
<<
/Type /FontDescriptor
/Ascent 720
/CapHeight 660
/Descent -270
/Flags 32
/FontBBox [-177 -269 1123 866]
/FontName /Helvetica-Bold
/ItalicAngle 0
....
PDF보기? 사전에
덕분에
정상적인 http 요청이 아닌 왜 아약스 요청이 필요한가요? 당신은로드 된 DOM을 잃지 않도록 첨부 파일에 내용 처리를 설정하고 있습니다. – planetjones
내 오류는 httpResponse.getOutputStream(). write (bais.toString(). getBytes ("UTF-8")); .. 그리고 나는 아약스에서 나갈거야 .. tks –