Method of passing parameter garbled in JSP page URL

Source: Internet
Author: User
Tags tomcat

JSP page passing parameters in the URL will appear garbled

The workaround is as follows:

First, use the method of changing Tomcat. This method is simple, but need to change the location of the server software level, if a slight change in the system will not be correct transcoding, the transplant is not high.

1, came to the Tomcat directory, to find the server.xml price, open, find the label, in the final add uriencoding= ' GBK ', the effect is as follows:

View Plaincopy to Clipboardprint?

  

port= "8080" maxthreads= "minsparethreads=" maxsparethreads= "75"

Enablelookups= "false" redirectport= "8443" acceptcount= "100"

debug= "0" connectiontimeout= "20000"

Disableuploadtimeout= "true" uriencoding=″gbk″/>

  

This method tests success on Get this method.

2. Add the following code to each JSP page

View Plaincopy to Clipboardprint?

<% @pagepageEncoding = "gb2312″%>

<% @pagecontentType = "text/html;charset=gb2312″%>

<%request.setcharacterencoding ("Gb2312″");%>

<%@ 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. Reboot Tomcat, this step is important, otherwise you may not see the effect.

This method succeeds for the post test. Two kinds of synchronous use are recommended.

Second, the use of JSP Scriptlet

View Plaincopy to Clipboardprint?

<%=newstring (Elvalue.getbytes ("iso-8859-1"), "GBK")%>

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

Iii. Use of custom Jstl

This is our focus, here to explain.

First, write a custom label

Second, write tag file

Third deployment Tag file

Use it four; it's simple.

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.