Hii伙计!!! 我生成了一个简单的参数化jasper报告,用于将数据导出为pdf formate.Now根据我的代码,pdf文件通过自动下载生成和打开,而我需要Saveas Dialogue Box要求openwith或saveas ...任何建议将不胜感激.. .Thanx提前......这是我的代码......
ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("para.jasper");
try {
String name = request.getParameter("name");
System.out.println(name);
String query = "Select * from vikas where vikas.name='" + name + "'";
System.out.println(query);
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/techsoft?user=root&password=techsoft");
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(resultSet);
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, new HashMap(), resultSetDataSource);
resultSet.close();
statement.close();
connection.close();
servletOutputStream.flush();
servletOutputStream.close();
答案 0 :(得分:0)
您应该添加Content-Disposition
http header。同时添加Content-Type
response.setHeader("Content-Type", "application/pdf");
response.setHeader("Content-Disposition", "inline; filename=\"" + getFileName() + "\"");