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());

私は何を間違っていますか?

4

1 に答える 1

0

私はもっ​​と多くの研究の後に解決策を見つけました。それが私の問題を解決した方法でした:Javaアプリケーションからサーブレットを呼び出す

于 2012-07-05T12:13:05.117 に答える