URL in the parameter content contains & compliance, I have two ways to solve
One method is: In the page with JS transcoding, examples are as follows (front-end processing)
<<a href= "#" onclick= "Test (' ${group.type} ', ' ${group.cn} ')" >${group.cn} "</a>
<script language= "JavaScript" >
function Test (a,b) {
alert ("test");
location.href= ' groupsdetailservlet?grouptypefordetail= ' + A + ' &cn= ' + encodeuricomponent (b);
}
</script>
The second method is: in the back-end processing
1>>>>>>>>>>>>>>>>>>>>jsp:
<a href= "GROUPSDETAILSERVLET?CN=${GROUP.ENCODEDCN}&grouptypefordetail=${grouptype}" +>${ group.cn}</a>
2>>>>>>>>>>>>>>>>>>>>java bean:group
String cn;//the CN
to display
String encodedcn;//the CN
when the parameter is passed
public Group (String cn) {this (); this.cn = cn; THIS.ENCODEDCN =ldaputil.encodeurlstr (CN);
public void Setcn (String name) {this.cn = name; SETENCODEDCN (Ldaputil.encodeurlstr (CN));
public String GETCN () {return cn;}
public String GETENCODEDCN () {return ENCODEDCN;}
public void Setencodedcn (String cn) {THIS.ENCODEDCN = cn;}
3>>>>>>>>>>>>>>>>>>>> The calling class to process the decoding:
String cn = Ldaputil.decodeurlstr (ENCODEDCN);
4>>>>>>>>>>>>>>>>>>>>ldaputil.java
public static string Encodeurlstr (String src)
{
return src!= null && src.trim (). Length () > 0? src.replaceall ("&", "@"): "";
}
public static string Decodeurlstr (String src)
{
return src!= null && src.trim (). Length () > 0? src.replaceall ("@", "&"): "";
}
--------------------------------------The following is-----web search data sharing---------------------------------------------------------- ------------------
When you use a URL for parameter passing, you often pass some parameter or URL address with a Chinese name (or a special character), and a conversion error occurs in the background processing. When you use GB2312 on some delivery pages and use UTF8 on the receiving page, the parameters you receive may be inconsistent with what you originally received. URLs encoded using the server-side UrlEncode function are not the same as URLs encoded using the encodeURI function of client JavaScript. JavaScript encodes text involves 3 functions: Escape,encodeuri,encodeuricomponent, corresponding 3 decoding functions: Unescape,decodeuri,decodeuricomponent encoding methods in
javascript:
Escape () method: encodes the specified string with the ISO Latin character set. All spaces, punctuation, special characters, and other non-ASCII characters will be converted into%XX-formatted character encodings (XX equals the encoded 16 digits of the character in the character set table). For example, spaces's corresponding encoding is%20. The Unescape method is the opposite. Characters that will not be encoded by this method: @ */+
encodeURI () method: Converts the URI string into a string in escape format using the UTF-8 encoding format. Characters that will not be encoded by this method:! @ # $& * () =:/;? + '
encodeURIComponent () method: Converts the URI string into a string in escape format using the UTF-8 encoding format. This method encodes more characters than encodeURI (), such as/or characters. So if a string contains several parts of the URI, this method cannot be encoded, otherwise the URL will display an error after the/character is encoded. Characters that will not be encoded by this method:! * ( )
therefore, for Chinese strings, you only need to use escape if you do not want to convert the string encoding format into a UTF-8 format (such as when the original page and the target page charset are consistent). If your page is GB2312 or other code, and the page that accepts the parameter is UTF-8 encoded, you should use encodeURI or encodeuricomponent.
in addition, Encodeuri/encodeuricomponent was introduced after javascript1.5, and escape was in the javascript1.0 version.
1, when passing parameters need to use encodeuricomponent, so that the combination of URLs will not be # and other special characters truncated. For example: <script language= "JavaScript" >document.write (' <a href= ' http://passport.baidu.com/?logout&aid=7 &u= ' +encodeuricomponent ("http://cang.baidu.com/bruce42") + ' "> Exit </a>");</script>
2, the URL jump can be used as a whole encodeuri. For example: Location.href=encodeuri ("http://cang.baidu.com/do/s?word= Baidu &ct=21");
3, JS use of data can use escape. For example: History records in the search of Tibet.
4, Escape to encode the Unicode value other than 0-255 output%u**** format, in other cases escape, encodeURI, encodeURIComponent encoding results are the same.
the most used should be encodeuricomponent, it is the Chinese, Korean and other special characters into the utf-8 format of the URL encoding, so if the background pass parameters need to use encodeuricomponent need to decode the background utf-8 Support (the form is encoded in the same way as the current page encoding)
escape does not encode 69 characters: *, +,-,.,/, @, _, 0-9, A-Z, A-Z
encodeURI not encoded characters have 82:!, #, $, &, ', (,), *, +,,,-,.,/,:,;, =,?, @, _, ~, 0-9, A-Z , A-Z
encodeuricomponent not encoded characters have 71:!, ', (,), *,-,., _, ~, 0-9, A-Z, a-Z
the following are the Fu Jie values in the URL that may be used in the URL: (abbreviated)
Project found that directly to the parameter part of the URL to do encodeURI () encoding conversion, the background servlet through Getparamater () acquisition, do not need to convert can directly obtain the correct value. Description: The parameters are not used in Chinese, the framework is a struts framework