This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Diplaying TIFF in Applet through JSP

 
Alpesh Khunt
Greenhorn
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 {

@Override
public void init() {
URI FileName = URI.create(getCodeBase().toString().concat(getParameter("imageSource")));
try
{
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();
//getContentPane().add(desktop,BorderLayout.CENTER);
desktop.setSize(400,400);
add(desktop,BorderLayout.CENTER);
// 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)));
jif.setSize(400,400);
jif.pack();
jif.setVisible(true);

// Add the internal frame to the JDesktop.
desktop.add(jif);
}
// Set the application closing behaviour, frame size, and show it.
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setVisible(true);
}
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"/>
</APPLET>



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
Rancher
Pie
Posts: 42967
73
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic