1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <%@page import="java.io.FileInputStream";%>
<%@ page import=" java.io.IOException";%>
<%
if (session.getAttribute("FILE") != null) {
try {
// Get image file.
FileInputStream in = new FileInputStream(session.getAttribute("FILE").toString());
// Get image contents.
int length = in.available();
byte[] bytes = new byte[length];
in.read(bytes);
in.close();
// Write image contents to response.
response.setContentType("image/jpg");
response.setContentLength(length);
response.getOutputStream().write(bytes);
// context.responseComplete();
} catch (IOException e) {
System.out.println("Showing image failed, I/O error");
}
}
%> |