I am using URL encode in my servlet program to replace spaces. I need to change the + value with %20. Is there any way to do it since if I use URL encode its outputting "+" instead of "%20".
I am using URL encode in my servlet program to replace spaces. I need to change the + value with %20. Is there any way to do it since if I use URL encode its outputting "+" instead of "%20".
Thanks.
If you're using Java 1.4 or later, use String.replaceAll().
...depending on what he has in mind. If he's trying to generate URL's, then a URLEncoder probably really is the right thing to use. But then again, URLEncoder doesn't solve the problem explicitly stated in the original post.
However, it may just be that he wanted to change spaces to %20 for other reasons, saw the URLEncoder, tried it, and found that it was a bad fit for his application after all.
I was just assuming he knows what he wants to do even if he doesn't know how to do it and I don't know why he wants to. I also assume that if he tried URLEncoder and it changed spaces to +s, he would verify that +s are wrong for his purposes before posting the question.
Of course I could be wrong.
Ryan
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, that will fit in a stocking