Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

URL Encoding

Posted on 2006-05-31
5
Medium Priority
?
243 Views
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:

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.

0
Comment
Question by:jeandp
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

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

http%3A%2F%2Fwww.somedomain.com%2Fpage.jsp%3Fa%3D123%26b%3D345%26c%3D567
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:jeandp
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?
0
 
LVL 16

Accepted Solution

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

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