The coding problem after Apache+tomcat integration

Source: Internet
Author: User

Apache+tomcat Integration provides webserver services for two purposes: one is to facilitate the use of Apache HTTP server to balance customer requests to tomcat1,tomcat2 .... To deal with, that is, load balancing, and because Tomcat's HTML and image parsing capabilities are weaker than other servers such as Apche, they are generally integrated and only JSP and servlet services are handed to Tomcat, while static content is done by Apache.

Using Apache's MOD_JK module and Tomcat's AJP protocol, we implemented this integration in the application, but during the test, we found that the URL containing Chinese characters (such as a picture or file of a user-uploaded Chinese file name) could not be accessed via Apache, returning 404 errors, Originally thought is Apache coding problem, because previously on Linux configuration Apache often occur this problem, so has been around the Apache httpd.conf in the language and charset configuration for the article, half a day did not fruit, depressed!!!

It suddenly occurred to me that it was normal to access Tomcat directly through IP and port, so the problem occurred between Apache and Tomcat, and the idea was suddenly enlightened. Open the Tomcat configuration file Server.xml, and find the configuration as follows: <connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" Redirectport= "8443" uriencoding= "UTF-8"/> <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/> Here, access to 8080 port (HTTP) specifies that the URI encoding takes UTF-8, while 8009 Port (AJP) does not specify the encoding. Since unspecified, Tomcat lacks the capital to use iso-8859-1 code, no wonder Chinese characters all become garbled!!! The operating system received a garbled path can not be located, the server had to give a resource path can not access the 404 error. So immediately to the AJP port also add uriencoding= "UTF-8", become: <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443" uriencoding= " UTF-8 "/>

Restart Tomcat, everything is OK, the world is set.

Summary one: The problem of URL coding with Chinese characters has always been the most headache, especially when multi-system integration often garbled problems. Therefore, it is particularly important to maintain the consistency of the Chinese character coding in each subsystem or submodule. For non-Chinese systems, the code in its default configuration often ignores this problem.

Summary two: The default settings of IE, URLs are submitted in UTF-8 encoding format, apache2.2 later versions of Windows default URL decoding is also utf-8, and when apache2.2 passes the request through AJP to Tomcat, it must be ensured that Tomcat also uses the Utf-8 codec on that port, otherwise it will be garbled.

The coding problem after Apache+tomcat integration

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.