Garbled characters may occur when parameters are passed in the URL on the JSP page.

Source: Internet
Author: User

Garbled characters may occur when parameters are passed in the URL on the JSP page.

The solution is as follows:

1. Use the method to change tomcat. This method is simple, but it must be modified at the server software level. If the system is slightly changed, transcoding cannot be performed correctly and portability is not high.

1. Go to the Tomcat directory, find the server. xml price under the conf directory, open it, find the <connector> tag, and add uriencoding = 'gbk' at the end. The effect is as follows:

<Connectorport="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"enableLookups="false" redirectPort="8443" acceptCount="100"debug="0" connectionTimeout="20000"disableUploadTimeout="true" URIEncoding=″GBK″/>

This method is successfully tested for the get method.

2. Add the following code on each JSP page:

<%@ page pageEncoding=”gb2312″%><%@ page contentType=”text/html;charset=gb2312″%><%request.setCharacterEncoding(”gb2312″);%>

The encoding method can also be changed to GBK, which supports traditional Chinese. Restart tomcat. This step is very important; otherwise, the effect may not be visible.

This method is successfully tested for post. We recommend that you use two types of synchronization.

Ii. use JSP scriptlet

<%=new String(elValue.getBytes("iso-8859-1"),"GBK")%>

3. Use custom jstl

This is our key point, which should be described in detail here.

First, write custom tags

Second, compile the Tag file.

Third, deploy the Tag file

Fourth, use it.) It's very simple.

<To be continued... add the above when you are free>

Related Article

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.