Forums Register Login

Displaying Images

+Pie Number of slices to send: Send
My code gives me no error or anything but justs keeps on working w/o doign the right thing...
Code...
package gsptech.portal.servlets;
import java.lang.*;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.*;
import java.util.Properties;
import gsptech.portal.biz.*;
import gsptech.portal.beans.*;
import java.sql.Timestamp;
import java.net.*;
import java.awt.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.io.IOException;
public class ImageServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
String file = req.getParameter("image");
int start = file.lastIndexOf('.') + 1;
int end = file.length();
String ext = "";

//Make sure that an extension exists
if (start != 0)
{
ext = file.substring( start, end );
System.out.println("@@@@@@@@@@@@@@@@@@@@@@" + ext);
if( ext.equalsIgnoreCase("jpg") | ext.equalsIgnoreCase("jpeg"))
JPEG(file, res);

if (ext.equalsIgnoreCase("gif"))
GIF(file, res);
}
}
private void GIF(String f, HttpServletResponse res)
{
try
{System.out.println("1ssssssssssssssssss" + f);
Image image = com.sun.jimi.core.Jimi.getImage(f);
System.out.println("2ssssssssssssssssss" + f);
OutputStream out = res.getOutputStream();
System.out.println("3ssssssssssssssssss" + f);
net.jmge.gif.Gif89Encoder gifenc = new net.jmge.gif.Gif89Encoder(image);
System.out.println("4ssssssssssssssssss" + f);
gifenc.encode(out);
System.out.println("5ssssssssssssssssss" + f);
}
catch(Exception e)
{
System.out.println("Problem rendering image" + e);
}
}
private void JPEG(String f, HttpServletResponse res)

{
try
{
FileInputStream fis = new FileInputStream(f);

JPEGImageDecoder decode = JPEGCodec.createJPEGDecoder((InputStream)fis);

BufferedImage img = decode.decodeAsBufferedImage();

OutputStream out = res.getOutputStream();

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

encoder.encode(img);
System.out.println("ssssssssssssss" + f);
}
catch(Exception e)

{
System.out.println("Problem rendering image" + e);
}
}
}
*****************************************
Output from Screen:
@@@@@@@@@@@@@@@@@@@@@@gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/PreviousArrow.
gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/blueline.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/NextArrow.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/TOCIcon.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/check.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/otherIcon.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/butlersm.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/helloWorld.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/prompt.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/sourceIcon.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/arrow.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/typea2.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/firstls.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/notequal.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/secondls.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/result.gif
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/tutorialIcon.g
if
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/applet_unix.gi
f
@@@@@@@@@@@@@@@@@@@@@@gif
1ssssssssssssssssss/var/gsp/portal_docs/middle_content/Operations/typeA.gif
+Pie Number of slices to send: Send
Near as I can tell, you are not setting the response content type or the content length. Setting content type is essential and many browsers need the content length too.
Bill
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 732 times.
Similar Threads
Image Servlets
Displaying graphics in a JSP
NoClassDefFoundError
Servlet displaying an image
Rotate an Image on server side
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:59:02.