Let Tomcat displays pictures (JDK1.4, Tomcat4.0 or later)

xiaoxiao2021-03-06  56

1. Steps:

Modify $ catalina_home / bin / catalina.sh file ($ CATALINA_HOME means the Tomcat installation directory), adding about 40 lines of the original file Add the following

Catalina_opts = "- djava.awt.Headless = True"

The deployment is complete. Very simple :))))

2. Test:

2.1 establish a directory

CD / usr / local / Tomcat / WebApps /

Mkdir -P testimage / web-inf / classes

2.2 Write index.jsp

Built index.jsp in / usr / local / tomcat / webapps / testimage directory, the content is as follows:

<% @ page import = "java.awt. *, java.awt.image. *, java.io. *, com.sun.image.codec.jpeg. *"%> <% bufferedimage bi = new bufferedimage (200 , 100, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics (); g.drawString ( "test java image", 0, 45); FileOutputStream fos = new FileOutputStream (application.getRealPath ( "/") "test. JPG "); JPEGIMAGEENCODER JPEGIE = ​​JPEGCODEC.CREATEJPEGENCODER (FOS); JPEGIE.Encode (BI); fos.close ();%>

2.3 operation

Start Tomcat, open your browser, enter:

Http: // localhost: 8080 / testimage

3. Postscript

3.1 Solutions flowing online, most to install XVFB, and then specify the system default x server as XVFB. But I use this method, the X Window comes into the system. Solving this additional question is very hard, I have no strength to study, I know that friends can reply below this document, thank you.

3.2 Some people have mentioned the headless support, but always say that the headless support is invalid in the Java original file, because Tomcat does not support no headless support. But why didn't they think of the headless support when Tomcat started? Well, 874 These people also went to the guys.

转载请注明原文地址:https://www.9cbs.com/read-114217.html

New Post(0)