Escaping & in a URL

前端 未结 4 1964
孤城傲影
孤城傲影 2021-01-11 23:42

I am using jsps and in my url I have a value for a variable like say \"L & T\". Now when I try to retrieve the value for it by using request.getParameter I

4条回答
  •  执念已碎
    2021-01-12 00:39

    You need to "URL encode" the parameters to avoid this problem. The format of the URL query string is: ...?=&=& All s and s need to be URL encoded, which basically means transforming all the characters that could be interpreted wrongly (like the &) into %-escaped values. See this page for more information: http://www.w3schools.com/TAGS/ref_urlencode.asp

    If you're generating the problem URL with Java, you use this method: String str = URLEncoder.encode(input, "UTF-8");

    Generating the URL elsewhere (some templates or JS or raw markup), you need to fix the problem at the source.

提交回复
热议问题