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:

http://mydomian.com/servlet/name?param1=abc¶m2=def&returnurl=http://www.somedomain.com/page.jsp?a=123&b=345&c=567

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.

jeandpAsked:
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(); }
0
 
Peter KwanAnalyst ProgrammerCommented:
Try to escape the returnurl as following:

http%3A%2F%2Fwww.somedomain.com%2Fpage.jsp%3Fa%3D123%26b%3D345%26c%3D567
0
 
jeandpAuthor Commented:
thx, is there anyway to encode the url with java code so that it looks like that
0
 
Peter KwanAnalyst ProgrammerCommented:
you may use java.net.URLEncoder.encode(url) method.
0
 
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?
0
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.