• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error Diplaying TIFF in Applet through JSP  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.io.IOException;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.widget.DisplayJAI;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
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
Posts: 42972
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!