I had # symbol to pass as parameter in my URL. But it is discarding all the parameter values after #. Kindly suggest me solution. Following is my url
GetConnectiont?
customerID=customer1&activenode=Sv50&parent=server&frame=imHealthCheckFrame&
connectedFrom=healthCheck&username=root&password=anil#1234&fromAskUsrPwd=askPassword
Thanks in advance
I had # symbol to pass as parameter in my URL. But it is discarding all the parameter values after #. Kindly suggest me solution. Following is my url
GetConnectiont?
customerID=customer1&activenode=Sv50&parent=server&frame=imHealthCheckFrame&
connectedFrom=healthCheck&username=root&password=anil#1234&fromAskUsrPwd=askPassword
Thanks in advance
Share Improve this question edited Apr 4, 2014 at 12:06 ANILBABU asked Nov 5, 2013 at 11:06 ANILBABUANILBABU 3872 gold badges6 silver badges21 bronze badges 1- How are you reading that parameter in your Servlet? – Mark Thomas Commented Nov 5, 2013 at 23:18
3 Answers
Reset to default 10Per the answer found here: How to escape Hash character in URL
Replace #
with %23
.
You can find a list of all the reserved characters here: Percent-encoding.
A word on JavaScript encoding
encodeURI(str)
"Assumes that the URI is a plete URI, so does not encode reserved characters that have special meaning in the URI.
encodeURI
replaces all characters except the following with the appropriate UTF-8 escape sequences:" [1]
encodeURIComponent(str)
"Escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )" [2]
In your case, you would use encodeURIComponent()
, only on your query string, to escape any and all reserved chracters.
! %21
# %23
$ %24
& %26
' %27
( %28
) %29
* %2A
+ %2B
, %2C
/ %2F
: %3A
; %3B
= %3D
? %3F
@ %40
[ %5B
] %5D
You would need to encode the parameters that may contain #
and then decode back the parameter in server side code.
You can use many resources in the internet to URL-encode strings, like this. In your case, anil#1234
bees anil%231234
.
You need to encode the value(if you are using string concatenation to create the url). in javascript you can use encodeURIComponent() like
encodeURIComponent('anil#1234');//or your variable here