2012-07-04 2 views
0

JasperPrint 객체를 PDF로 변환하고 도 새 탭에서이 PDF를 여는 서블릿을 만들었습니다. 하지만 내 코드 호출자가 내 서블릿을 호출하지 않고 어떤 예외도 발생시키지 않는 것 같습니다.자바 클래스에서 서블릿 호출

브라우저에서 직접 URL을 호출하면 서블릿이 호출되지만 내 Java 클래스에서는 동일하지 않습니다.

호출자 코드 :

URL url = new URL("http://localhost:8080/app/reportgenerator"); 
HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 

connection.setRequestMethod("POST"); 
connection.setDoInput(true); 
connection.setDoOutput(true); 
connection.setUseCaches(false); 
connection.setDefaultUseCaches (false); 
connection.setRequestProperty("Content-Type", "application/octet-stream"); 

ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream()); 
JasperPrint jasperPrint = new JasperPrint(); 
out.writeObject(jasperPrint);   
out.close(); 

서블릿 코드 : 내가 잘못 뭐하는 거지

response.setContentType("application/pdf"); 
response.setHeader("Content-Disposition","attachment; filename=\"report.pdf\""); 

JasperPrint jasperPrint = null; 

try { 
    ObjectInputStream resultStream = new ObjectInputStream(request.getInputStream()); 
    jasperPrint = (JasperPrint) resultStream.readObject(); 
    resultStream.close(); 

    JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); 

?

+1

그래서 자바에서 호출하면 어떻게됩니까? 어떤 오류가 있습니까? 스택 추적을 게시 할 수 있습니까? –

+0

아니요, 오류가 발생하지 않았습니다. 그것은 정말 이상한 일이었습니다. 그러나 해결책을 찾았으며 아래 답변에서 그것을 공유했습니다. 어쨌든 –

+0

[Java 응용 프로그램에서 서블릿 호출하기]의 복제본을 보내 주셔서 감사합니다. (http://stackoverflow.com/questions/4349854/calling-a-servlet-from-a-java-application) – FoamyGuy

답변