Regards.
Lionel.
Code :
import javax.swing.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JpegDisplay extends HttpServlet {
File file = new File("/home/mon_image.jpg");
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
ServletOutputStream out = res.getOutputStream();
ImageIcon imgIcon = new ImageIcon(this.getFileToByteArray(file));
res.setContentType("image/jpeg");
out.write(this.getFileToByteArray(file));
}
private byte[] getFileToByteArray(File pFile)
{
byte[] tmpBuffer = null;
if (pFile!=null)
{
FileInputStream fileStream = null;
try{
fileStream = new FileInputStream( pFile );
} catch (java.io.FileNotFoundException e) {
System.err.println("WARNING : File not found");
}
tmpBuffer = new byte[ (int)pFile.length() ];
try{
fileStream.read(tmpBuffer);
}catch (java.io.IOException e) {
tmpBuffer = null;
System.err.println("WARNING : Impossible to translate file
in byte[]");
}
}
return tmpBuffer;
}
}
error sous linux :
java.lang.NoClassDefFoundError: sun/awt/motif/MToolkit at
org.apache.jserv.JServConnection.processRequest(JServConnection.java:327)
at org.apache.jserv.JServConnection.run(JServConnection.java:197)
at java.lang.Thread.run(Thread.java:479)
I suspect this is due to the servlet not having an X-server to connect
to. If you can set the DISPLAY environment variable in the shell that the
servlet runs in, you should be able to run an X server (such as Xvfb) for
Java to "talk to". This whole problem is being fixed in JDK 1.4, btw.
--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet/
----------------------------------------------------------------------
Subject: Re: Problems with images in servlets (classes not found)
From: "=C1sta Herd=EDs Hall" <a...@hi.is>
Date: Wed, 26 Jan 2000 10:59:21 -0000
I just wanted to let you know that I have gotten this to work, finally,
thanks to your answers. What I ended up doing was as follows:
1. Add the line wrapper.env=3DDISPLAY=3Dlocalhost:0 to my jserv.properti=
es file
2. Gave permission to connect to the Xserver from localhost: xhost +
localhost
3. started the Xserver with DISPLAY 0 as an ordinary user.
4. started JServ manually with DISPLAY 0, using the following script:
#!/bin/sh
properties=3D/usr/local/jserv/etc/jserv.properties
log=3D/usr/local/jserv/logs/jserv_manual.log
CLASSPATH=3D$CLASSPATH:/usr/local/JSDK2.0/lib/jsdk.jar
CLASSPATH=3D$CLASSPATH:/usr/local/jserv/libexec/ApacheJServ.jar
java org.apache.jserv.JServ $properties $1 2>> $log
Thank you very much for your help. I will add your answers to the faq as=
it
might save someone some time.
=C1sta
----- Original Message -----
From: Richard Hallier <in...@fivia.com>
To: Java Apache Users <java-apa...@list.working-dogs.com>
Sent: Monday, January 24, 2000 6:48 PM
Subject: RE: Problems with images in servlets (classes not found)
Jon Skeet <sk...@pobox.com> a écrit dans le message :
MPG.142a8f7e69ace51298a682@news...
> lpe...@connectsuite.com wrote:
> > Hello,
> > This servlet can display an image if it run under MS NT server. But it
does
> > not work under GNU/Linux RedHat 6.0 server.
> > Does anybody knows about this problem ?
> > Is it possible to a servlet to read a jpeg image into a frame, modify
it,
> > and then return an encoded jpg stream as response with Linux.
>
There are plenty of reactions from Sun, one of which is "headless Java"
for 1.4, where you don't need an X server to do such things...
Another way is http://www.eteks.com/pja/en/
Why not...
Jon Skeet <sk...@pobox.com> a écrit dans le message :
MPG.142af5e7fd99dab198a684@news...
Well, I think having a nicely searchable bug file which gives a
workaround is a fair amount of communication...
Jon> lpe...@connectsuite.com wrote:
>> I was talking about the lack of communication from Sun (for me
>> of course).
Jon> Well, I think having a nicely searchable bug file which gives
Jon> a workaround is a fair amount of communication...
Also, searching the usenet archives should show numerous answers to
this question.
BTW, there is a second solution for problem: The 'Pure Java AWT
Toolkit' (http://www.eteks.com/pja/en/)
Juergen
--
Juergen Kreileder, Blackdown Java-Linux Team
http://www.blackdown.org/java-linux.html
JVM'01: http://www.usenix.org/events/jvm01/
Jon Skeet <sk...@pobox.com> a écrit dans le message :
MPG.142c0ae72948cf4c98a696@news...
> lpe...@connectsuite.com wrote:
> > I was talking about the lack of communication from Sun (for me of
course).
>
> Well, I think having a nicely searchable bug file which gives a
> workaround is a fair amount of communication...
>
Well, Sun hosts it and have replied to it. Given that all the information
is there on their site, it would seem silly to require them to do *more*
to communicate about it, wouldn't it?
I agree it's an irritating problem though.