• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying graphics in a JSP

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Thanks Rob."
No problem.
"Do I need to do this in catalina.sh?"
That sounds reasonable.
Later.
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried SVG(Scalable Vector Graphics)?
 
Tim Eyre
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rene, Sanpra,
etek merely brought down Tomcat.
What is SVA?
Thanks
Tim
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic