aspose file tools*
The moose likes JSP and the fly likes Displaying graphics in a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying graphics in a JSP" Watch "Displaying graphics in a JSP" New topic
Author

Displaying graphics in a JSP

Tim Eyre
Greenhorn

Joined: May 20, 2002
Posts: 20
I am trying to display some graphics in a JSP.
I have tried using a JPEGImageEncoder to convert from Graphics2D into a JPEG, but I get the error: "Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable"
Other questions on the forum have suggested installing X-windows on my pc, but the app I'm writing runs on unix and is to be used by many users - I can't install X-windows on all of their pc's.
Does anyone know how to get round this?
Or does anyone know a better way of displaying graphics in a JSP/Servlet.
Thanks
Tim
Rob Misek
Ranch Hand

Joined: Sep 24, 2002
Posts: 41
Hi Tim,
I ran into this problem running Orion on Solaris, I believe that you _only_ have to install x-windows on the server, _not_ all the client PCs.
Later.


<a href="http://www.tangosol.com" target="_blank" rel="nofollow">www.tangosol.com</a><br /><a href="http://www.tangosol.com/coherence.jsp" target="_blank" rel="nofollow">Coherence:</a> Easily share live data across a cluster!
Rob Misek
Ranch Hand

Joined: Sep 24, 2002
Posts: 41
[...]
I am remembering more now.
I think you can also set the DISPLAY env var to go to a UNIX machine that _has_ x-windows installed (if you have one laying around) and that will work as well.
Later.
Tim Eyre
Greenhorn

Joined: May 20, 2002
Posts: 20
Thanks Rob.
Do I need to do this in catalina.sh?
Tim
Rob Misek
Ranch Hand

Joined: Sep 24, 2002
Posts: 41
"Thanks Rob."
No problem.
"Do I need to do this in catalina.sh?"
That sounds reasonable.
Later.
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
Not complete code but shoudl help...
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
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);

}
catch(Exception e)

{
System.out.println("Problem rendering image" + e);
}
}
sanpra sing
Greenhorn

Joined: Aug 28, 2002
Posts: 15
Hi tim,
I tried this on windows and it works fine.(I got the same error on linux. I think if you have Xwindows running on the server this will work. I couldn't try this since I do not have a monitor attached to my linux box and I can't try the easy way of running a xserver (i.e. xwindows)). What I want to know why do you need to do this?I cant think of much use for this. Could you reply?
Tim Eyre
Greenhorn

Joined: May 20, 2002
Posts: 20
Sanpra,
Thanks for the advice. I am trying it now...
I want to display some graphs and charts in a JSP. If you know a better way of doing it rather than converting into JPEG and embedding within the HTML, then please let me know.
Thanks
Tim
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

One way could be - use J2SDK 1.4.x
or try this link: http://www.eteks.com/pja/en/
Rene
[ October 11, 2002: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
sanpra sing
Greenhorn

Joined: Aug 28, 2002
Posts: 15
Have you tried SVG(Scalable Vector Graphics)?
Tim Eyre
Greenhorn

Joined: May 20, 2002
Posts: 20
Rene, Sanpra,
etek merely brought down Tomcat.
What is SVA?
Thanks
Tim
David Gilbert
Ranch Hand

Joined: Jun 01, 2002
Posts: 42
Hi Tim,
This thread in the JFreeChart forum might help you:
http://www.object-refinery.com/phorum-3.3.2a/read.php?f=2&i=4783&t=2987
You might also want to check out Cewolf, a tag library based on JFreeChart:
http://cewolf.sourceforge.net
Regards,
Dave Gilbert
JFreeChart Project Leader
Paul Frey
Greenhorn

Joined: Apr 25, 2002
Posts: 19
I use Xvfb to supply the X server. This allows the java applications to run without a display (actually Xvfb creates a buffer for the display).


Paul G. Frey, Jr.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying graphics in a JSP