URL Encoding

Hi I have the following url problem.

I need to send a request to a servlet and also pass it a return url.

The return url is in this form: http://www.somedomain.com/page.jsp?a=123&b=345&c=567
The url that I need to hit is in this form:


The problem I have is that when I get the returnurl parameter it stops before the first & (http://www.somedomain.com/page.jsp?a=123) in the return url. I understand why it does this, I just need a solution so that I can get the full returnurl.

Thanx in advance.

Who is Participating?
Peter KwanAnalyst ProgrammerCommented:

you may use the following code:

 try {
System.out.println(URLEncoder.encode("http://www.somedomain.com/page.jsp?a=123&b=345&c=567", "UTF-8"));
} catch(java.io.UnsupportedEncodingException e) { e.printStackTrace(); }
Peter KwanAnalyst ProgrammerCommented:
Try to escape the returnurl as following:

jeandpAuthor Commented:
thx, is there anyway to encode the url with java code so that it looks like that
Peter KwanAnalyst ProgrammerCommented:
you may use java.net.URLEncoder.encode(url) method.
jeandpAuthor Commented:
thx, the java.net.URLEncoder.encode(url)  works, but its deprecated and I would like to avoid using a deprecated method. What is its replacement?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.