Question

I have passes a encoded SSO token in URL...so the URL looks like

 http://127.0.0.1:7101/CRMOD_UCM-Sankalp-context-root/BrowseFile.jsp?token=%246%24zhxjx%2fpz6dVucl9cgG43ii2Tr4qVnNbeqJg8jCy6Jj7vRvXN4%3d%3b%246%24GlRGp%2fxfEM308NZGmY%2fhjHav2yjHSvbww1l0%2fCcCtcVjzl%2bCQFlQPdBRKO0t1XUmF0I6xLmfQ%2fnb7VgJeSYnvrAb9YUQQ3tvr%2fBZ%2bIRZiBAGU2%2fZg%3d

but when i retreive the value of variable and print it using out.println("SSO Token:"+request.getParameter("token")); it prints

$6$zhxjx/pz6dVucl9cgG43ii2Tr4qVnNbeqJg8jCy6Jj7vRvXN4=;$6$GlRGp/xfEM308NZGmY/hjHav2yjHSvbww1l0/CcCtcVjzl+CQFlQPdBRKO0t1XUmF0I6xLmfQ/nb7VgJeSYnvrAb9YUQQ3tvr/BZ+IRZiBAGU2/Zg=

The correct token is which is present in the URL, WHY i am getting such a different value in my print...

Kindly help......

Was it helpful?

Solution

You are getting encoded value if you want decode then use following code. By default system decode for us but in your case it is not decoded and you must explicitly decode value of request.getParameter("token").

String token = request.getParameter("token").toString();
// To decode url
String decodedtoken = URLDecoder.decode(token , "UTF-8");
System.out.println("Decoded token value "+ decodedtoken);

// To encode url 
String encodedtoken = URLEncoder.encode(token , "UTF-8"); 
System.out.println("Encoded token value "+ encodedtoken);

OTHER TIPS

request.getParameter("token") decodes the parameter value, so the value that gets printed is the decoded version of the parameter value in the URL.

See Java EE, accent in url, request.getParameter wrong value for more information.

In the URL, the token is URL encoded. This is necessary because some characters have special meanings in an URL.

By URL encoding the value, those special characters are replaced by %nn codes where nn is the character code of the special character.

Java automatically decodes it for you, so that you get the actual value when you call request.getParameter("token") instead of the URL-encoded value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top