After converting the character set, the Chinese parameters of URL passing parameters in JSP are still subject to question marks.

Source: Internet
Author: User

Problem:

<A class = "a_ope" href = "hitinfoqueryservlet? Query_type = detail & music_singer = Hemingway "> details </a>Pass Chinese parameters through URL through click connection

The Chinese parameter of the URL in the hitinfoqueryservlet squadron is used to convert the character set recommended by most people.

The Code is as follows:New String (Singer. tostring (). Trim (). getbytes ("iso8859-1"), "UTF-8 ")Tomcat default character is iso8859-1

However, after conversion, the Chinese string becomes "Hamming ?" .

 

Solution:

Change the original connection<A class = "a_ope" href = "hitinfoqueryservlet? Query_type = detail & music_singer = <% = urlencoder. encode ("Hemingway", "UTF-8") %> "> details </a>Then, the servlet code remains unchanged, and you can still convert the character set.

Of course, in this example, the prerequisites are:

Response. setcharacterencoding ("UTF-8 ");
Request. setcharacterencoding ("UTF-8 ");
Response. setcontenttype ("text/html; charset = UTF-8 ");

If you want to change to another character set, replace UTF-8 with the character set you need.

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.