how to display uploaded jpeg in jsp(its urgent)
hi all,
i am upload image(jpeg) using FormFile.........
then i am trying to display it but it display the bytes only....
my code is as below....
jsp.
<html:form action="/viewImage.do" method="post" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" summary="Image table">
<tr>
<td align="right">Image </td>
<td align="left">
<html:file property="image" />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<html:submit property="saveImage">Upload Image</html:submit>
</td>
</tr>
</table>
</html:form>
------------------------my action is
public void disImage(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
CompanyImageForm companyImageForm = (CompanyImageForm)form;
FormFile myFile = companyImageForm.getImage();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
InputStream in = new ByteArrayInputStream(fileData);
BufferedImage image=javax.imageio.ImageIO.read(in);
response.setContentType(contentType);
OutputStream sos = response.getOutputStream();
ImageIO.write(image,"jpeg",sos);
}
thanks,
shaktish