Garbled characters in Chinese characters in JSP URLs

Source: Internet
Author: User
I

1. Insert the following code in server. xml under Tomcat:

<Connector Port = "8080" protocol = "HTTP/1.1" uriencoding = "UTF-8" usebodyencodingforuri = "true"

Connectiontimeout = "20000"
Redirectport = "8443" type = "regxph" text = "yourobjectname"/>

2. Encrypt parameters to be passed in JSP page JS

Encodeuri (PARAM)

2. Write in action

Request. setcharacterencoding ("UTF-8 ");

New String (urldecoder. Decode (PARAM). getbytes ("iso-8859-1"), "UTF-8") (not required)

II

Copy http://blog.csdn.net/woshixuye/article/details/7547710 below

JSP

VaR num = $ ("# txtnum"). Val ();
VaR name = encodeuricomponent ($ ("# txtname"). Val ());
VaR classname = encodeuricomponent ($ ("# selectclasses option: Selected"). Text ());

 

In action

Stu. setnum (urldecoder. Decode (Num, "UTF-8 "));
Stu. setname (urldecoder. Decode (name, "UTF-8 "));
Stu. setclassname (urldecoder. Decode (classname, "UTF-8 "));

Generally, the struts filter is automatically processed in post. In get, this operation is required.


Principle:

Encodeuricomponent is a built-in JS function that converts special characters such as Chinese and Korean into UTF-8 URL encoding.

If encodeuricomponent is required to pass parameters to the backend, backend decoding is required to support UTF-8

Note that the encoding method in form is the same as that on the current page.


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.