-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewnew2.jsp
62 lines (49 loc) · 1.89 KB
/
Viewnew2.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<%--
Document : Viewnew2
Created on : May 6, 2020, 7:07:22 PM
Author : Kavishka Wijesekera
--%>
<%@page import="java.util.logging.Logger"%>
<%@page import="java.util.logging.Level"%>
<%@page import="db.DBCon"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>View File</title>
</head>
<body>
<%
String id=(request.getParameter("id"));
Blob file = null;
byte[ ] fileData = null ;
try
{
DBCon dbconn=new DBCon();
Connection conn= dbconn.connectToDB();
String sqlString = "SELECT Image FROM stuevent WHERE id = '"+id+"'";
Statement myStatement = conn.createStatement();
ResultSet rs=myStatement.executeQuery(sqlString);
if (rs.next())
{
file = rs.getBlob("Image");
fileData = file.getBytes(1,(int)file.length());
} else
{
out.println("file not found!");
return;
}
response.setContentType("Image");
response.setHeader("Content-Disposition", "inline");
response.setContentLength(fileData.length);
OutputStream output = response.getOutputStream();
output.write(fileData);
output.flush();
} catch (SQLException ex) {Logger.getLogger(Logger.class.getName()).log(Level.SEVERE, null, ex);}
%>
<br><br>
</body>
</html>