Jsp Chinese parameter garbled

Source: Internet
Author: User

1. The request parameters on the request page need to be transcoded using encodeURI, and Character Set conversion is required on the page receiving the request. The character set of the request and receive page in this example are both UTF-8: 1. the requested JSP page uses the JavaScript encodeURI () method to transcode the parameter: function toView (param) {var encodeparam = encodeURI (param); window. location. href = "/naias/advAna_form.do? Method = showDetail & title = "+ encodeparam;} 2. perform Character Set conversion in the jump Action: www.2cto. compublic ActionForward excute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {String title = request. getParameter ("title"); title = new String (title. getBytes ("iso-8859-1"), "UTF-8"); System. out. println (title);} 2. For the JSP page parameter encoded as the UTF-8, there are two solutions for Chinese garbled characters: 1. use the GET method to pass the parameter, and use the new String (request . GetParameter (""). getBytes ("ISO-8859-1"), "UTF-8"); to convert to the desired encoding, such as a UTF-8. 2. Pass the parameter through POST, and declare the encoding type by declaring request. setCharacterEncoding ("UTF-8. 3. You can add a filter to solve Garbled text, but it does not work for parameters submitted in GET mode (that is, parameters passed through the address bar. 4. If you use the tomcat server, you can change the tomcat configuration file to set the character set encoding to UTF-8.

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.