Display tomcat images in Linux (jdk1.4, tomcat4.0 or later)

Source: Internet
Author: User
1. steps:
Modify the $ catalina_home/bin/Catalina. Sh file ($ catalina_home refers to the tomcat installation directory). Add the following content to the 40 lines of the original file:
Catalina_opts = "-djava. AWT. Headless = true"

Save the disk and exit. It's easy :)))

2. test:
2.1 create a directory
CD/usr/local/tomcat/webapps/
Mkdir-P testimage/WEB-INF/classes

2.2 compile index. jsp
Create index. jsp in the/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 ");

Required imageencoder required Ie = required codec. createJPEGEncoder (fos );

Using IE. encode (bi );

Fos. close ();
%>

2.3 run
Start tomcat, open the browser, and enter: http: // localhost: 8080/TestImage

3. Postscript
3.1Most of the solutions available on the Internet are to install xvfb, and then specify the default x server as xvfb. However, after using this method, the x window that comes with the system cannot be entered. It is very difficult to solve this additional problem. I have never been able to study it. If you know it, please reply below this document. Thank you.

3.2Some people have mentioned headless support, but it is always said that it is invalid to write headless support in the original java file, because tomcat is not started with Headless support. But why didn't they expect to add headless support during tomcat startup? Well, let's look at the 874 crowd.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.