Escape and url

I am using jsps and in my url I have a value for a variable like say "L and T". Now when I try to get the value for it using request.getParameter , I get only "L". It recognizes "&" as a delimiter and, therefore, is not considered a whole line.

How to solve this problem?

+7
java url uri jsp
source share
4 answers
 java.net.URLEncoder.encode("L & T", "utf8") 

this outputs the URL encoding, which is excellent as a GET parameter:

 L+%26+T 
+14
source share

The literal ampersand in the URL should be encoded as: %26

 // Your URL http://www.example.com?a=l&t // Encoded http://www.example.com?a=l%26t 
+1
source share

You need to β€œURL encode” parameters to avoid this problem. The format of the URL query string is: ...?<name>=<value>&<name>=<value>&<etc> All <name> and <value> should be encoded in the URL, which basically means converting all characters, which may be misinterpreted (e.g. &) into% -escaped values. See this page for more information: http://www.w3schools.com/TAGS/ref_urlencode.asp

If you create the URL of a Java problem, you use this method: String str = URLEncoder.encode(input, "UTF-8");

By creating the URL elsewhere (some patterns or JS or raw markup), you need to fix the problem in the source.

+1
source share

You can use UriUtils#encode(String source, String encoding) from Spring Web. This utility class also provides facilities for encoding only certain parts of a URL, such as UriUtils#encodePath .

0
source share

All Articles