File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Error Diplaying TIFF in Applet through JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Error Diplaying TIFF in Applet through JSP" Watch "Error Diplaying TIFF in Applet through JSP" New topic

Error Diplaying TIFF in Applet through JSP

Alpesh Khunt

Joined: Nov 18, 2008
Posts: 1
Dear All,

I've been trying to display the Tif image into the WebBrowser with the help of Applet embedded into a JSP through NetBeans IDE.

To achieve this goal, I've created 2 projects "NewApplet" which contains the Applet class and "WebApplication1" which has "Index.JSP" which embeds the Applet.

If i execute Only the Applet, it displays the TIF. But if i execute the JSP, it fires the following error:
"URL Scheme is not "file" http://localhost:8084/WebApplication1/alpesh.tif""

Following is the code written NewApplet.Java:

package display;

import javax.swing.JApplet;
import java.awt.BorderLayout;
import java.awt.image.RenderedImage;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;

public class NewApplet extends JApplet {

public void init() {
URI FileName = URI.create(getCodeBase().toString().concat(getParameter("imageSource")));
File f = new File(FileName);

FileInputStream stream = new FileInputStream(f);

// Create a decoder using that stream.
TIFFDecodeParam tiff = new TIFFDecodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, tiff);

// Get the number of pages.
int pages;
pages = dec.getNumPages();

// Set the application title.
setTitle(pages+" pages in "+filename);

// Create a JDesktop to hold the pages in internal frames.

JDesktopPane desktop = new JDesktopPane();
// Open all images in the TIFF into the desktop pane.
for(int i=0;i<pages;i++)
// Get the image.
RenderedImage ri = dec.decodeAsRenderedImage(i);
// Create and set the user interface of an internal frame.
JInternalFrame jif = new JInternalFrame("Page "+i,true,true,true,true);
jif.getContentPane().add(new JScrollPane(new DisplayJAI(ri)));

// Add the internal frame to the JDesktop.
// Set the application closing behaviour, frame size, and show it.
catch (Exception e)
JOptionPane.showMessageDialog(this, e.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);

Following is the code written Index.JSP:

<APPLET code="display.NewApplet" ARCHIVE="NewApplet.jar" width=350 height=200>
<param name ="imageSource" value="alpesh.tif"/>

Any Guesses?

I've added the "dist/NewApplet.jar" in WebApplication1 through the option of "Properties->Build->Packaging" in NetBeans.

Please help!

- Alpesh
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

You can't use file I/O (classes like File and FileInputStream) to work with images loaded from a server. You'll need to do something like

Do you need to use JAI? It would be simpler if you used ImageIO (which can be made to recognize TIFF images).

Also, in the future, please UseCodeTags when posting code of any length. It is unnecessarily hard to read as it is.
[ November 18, 2008: Message edited by: Ulf Dittmer ]
I agree. Here's the link:
subject: Error Diplaying TIFF in Applet through JSP
It's not a secret anymore!