I need to encode the URL in order to prevent XSS security threat. I don't have to encode the complete URL, I just have to encode the values for query string. Can you someone help on how to encode only the values of query string parameters and change it in the URL itself using java. I am planning to do this in a filter. Please help.