Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Two important Steps while reading an Image with a Servlet.
i) Getting the MIME type and setting to Response .
String mimeType =
getServletContext().getMimeType(filename);
res.setContentType(mimeType);
ii) Reading the Image in small chunks as follows
byte[] buf = new byte[1024];
public class ImageReader extends HttpServlet {
public void doGet(HttpServletRequest
req, HttpServletResponse res)
throws ServletException, IOException {
FileInputStream fis = null;
String
filename =
"C:/Img/yourOwn.jpg";
String
mimeType =
getServletContext().getMimeType(filename);
if
(mimeType == null) {
sc.log("Could not get MIME type of
"+filename);
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
res.setContentType(mimeType);
ServletOutputStream output =
res.getOutputStream();
try
{
fis = new FileInputStream(new
File(filename));
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
output.write(buf, 0, i);
}
output.flush();
} finally
{
fis.close();
output.close();
}
}
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.