当我执行这个jsp文件时,我可以下载pdf格式的文件。但是当我试图打开它时,它会显示一个不支持格式的错误。但是,如果我尝试在记事本中打开下载的 pdf 文件,我会得到我想要的数据。但我应该以解密的形式获得它。所以请帮我打开 pdf 文件以查看数据。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% String ID = (String) session.getAttribute("ID");
String connectionURL = "jdbc:oracle:thin:@localhost:1521:XE";
String url = request.getParameter("WEB_URL");
String Content = new String("");
Statement stmt = null;
Connection con = null;
String Content = new String("");
String filename = "data" + ID + ".pdf";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(connectionURL, "temp",
"root");
stmt = con.createStatement();
String qry = "select * from form where id='" + ID + "'";
ResultSet rst = stmt.executeQuery(qry);
if (rst.next()) {
Content = " FirstName: " + rst.getString("FirstName")
+ "\r\n" + " LastName: "
+ rst.getString("LastName") + "\r\n" + " Age: "
+ rst.getString("Age") + "\r\n" + " City: "
+ rst.getString("City") + "\r\n" + " Phone: "
+ rst.getString("Phone") + "\r\n" + " ID: "
+ rst.getString("ID");
}
//out.println(Content);
byte requestBytes[] = Content.getBytes();
response.reset();
response.setContentType("application/pdf");
response.setHeader("cache-control", "no-cache");
response.setHeader("Content-disposition",
"attachment; filename=" + filename);
response.setCharacterEncoding("UTF-8");
ByteArrayInputStream byteStream = new ByteArrayInputStream(
requestBytes);
BufferedInputStream bufStream = new BufferedInputStream(
byteStream);
ServletOutputStream responseOutputStream = response
.getOutputStream();
int data = bufStream.read();
while (data != -1) {
responseOutputStream.write(data);
data = bufStream.read();
}
bufStream.close();
responseOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println(" Exception is:" + e);
}
%>
</body>
</html>