Learn how to a build a cloud-first strategyRegister Now


URL Encoding

Posted on 2006-05-31
Medium Priority
Last Modified: 2010-04-01
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.

Question by:jeandp
  • 3
  • 2
LVL 16

Expert Comment

by:Peter Kwan
ID: 16796777
Try to escape the returnurl as following:


Author Comment

ID: 16796807
thx, is there anyway to encode the url with java code so that it looks like that
LVL 16

Expert Comment

by:Peter Kwan
ID: 16796927
you may use java.net.URLEncoder.encode(url) method.

Author Comment

ID: 16796942
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?
LVL 16

Accepted Solution

Peter Kwan earned 500 total points
ID: 16796985

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(); }

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question