Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying graphics in a JSP

 
Tim Eyre
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Misek
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[...]
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.
Do I need to do this in catalina.sh?
Tim
 
Rob Misek
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Thanks Rob."
No problem.
"Do I need to do this in catalina.sh?"
That sounds reasonable.
Later.
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sanpra sing
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried SVG(Scalable Vector Graphics)?
 
Tim Eyre
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene, Sanpra,
etek merely brought down Tomcat.
What is SVA?
Thanks
Tim
 
David Gilbert
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic