I use URLCodec from Apache Commons Codec to encode the url, but it encodes the space as + NOT like %20
URLCodec
+
%20
why? and what is the solution?
See this related question.
Of course, you can always do url.replace("+", "%20"); if you need it (after coding)
url.replace("+", "%20");
Because + is an equally valid way to encode a space. What are you trying to "solve"?
URLCodec encodes material corresponding to the submitted form, which does not match the percentage encoding the URL. There are more explanations in this matter.
See this question on how you should encode your URL.