File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes displaying an image of  type TIF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

displaying an image of type TIF

Santosh Raveendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 83
can any one advice on how to display an image of type TIF in a jsp

Thanks
santhosh
[ November 26, 2008: Message edited by: santosh raveendran ]

SCJP 1.4,SCWCD5, SCBCD5
Thanks, Santhosh
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
JSPs dont display images - they write HTML tags that tell the client browser where to get the image in a separate request/response cycle.

Get your image display working with static HTML tags first, then figure out how to get JSP to write that tag.

Bill
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41519
    
  53
Few (No ?) browsers can display TIFF out of the box. There's a plugin called http://www.alternatiff.com/ but it only works on Windows.

Maybe a better approach would be to convert the TIFF to something more universal -like PNG-, and serve that instead?


Ping & DNS - my free Android networking tools app
Santosh Raveendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 83
William,Ulf

I have implemented the below solution for displaying the image of extension tiff.

Struts implementation

public ActionForward execute(ActionMapping map, ActionForm form,HttpServletRequest request,
HttpServletResponse res) throws Exception {
System.out.println("Inside TiffFileDisplayAction");

FileInputStream inputStream;
byte[] buf = new byte[512 * 1024]; // 512K buffer
try {
//File file=new File("D://avinash//ss.pdf");
//inputStream=new FileInputStream(file);
//byte[] buf=new byte[inputStream.available()];
//inputStream.read(buf);

//String fileNames = "Example.pdf"; //(String) request.getParameter("fileNames");
//String fileExtension = fileNames.substring(fileNames.lastIndexOf('.')+1);
//inputStream = new FileInputStream("E://TifImage//Example.pdf");
inputStream = new FileInputStream("E://TifImage//Sample.tif");
//byte buf[]=new byte[1024];
int len;
res.setContentType("application/tiff");
res.setContentLength(buf.length);
//res.setHeader("Pragma", "no-cache");
res.setHeader( "Content-Disposition", "inline; filename=Sample.tif");
ServletOutputStream out = res.getOutputStream();
//out.write(buf, 0, buf.length);
while((len=inputStream.read(buf))>0)
out.write(buf,0,len);
out.close();

//buf = centeraService.retrieveFileFromCoupon(clipArtID);
//showPDFForScreen(buf,fileExtension);
//showPDFForScreen(buf,fileNames,fileExtension.trim(),res);

} catch (Exception e) {
e.printStackTrace();
}
return map.findForward("success");
}


Thanks
santhosh
 
 
subject: displaying an image of type TIF