aspose file tools*
The moose likes Servlets and the fly likes Special charecters in URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Special charecters in URL" Watch "Special charecters in URL" New topic
Author

Special charecters in URL

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

I need to pass special charecters in a querystring when I click on a hyperlink.

charecters like #, ^, spaces.. how to do it.

please help.

Thanks,
Neeraj.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1367
    
  18
Hi there,

If you find the hex value of the characters you need to pass in, you can use those.

the hexadecimal value for a space is 20, and in a URL you can encode this as %20
the caret is %5E
the pound character is %23

I'm sure some good references should come up if you google "url encoding" or "url hex encoding"
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

java.net.URLEncoder can do this for you.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

Thanks for the help.

but we are using jdk1.4 in our project. so looking for a different solution.

thanks,
Neeraj.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42918
    
  68
but we are using jdk1.4 in our project. so looking for a different solution.


That class has been there since Java 1.0.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

I was using eclipse 3.0. URLEncoder class gave error.

let me check and update.

Thanks,
Neeraj.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Follow the link I posted to that API page.
Notice that there is a deprecated version of encode and a newer version that takes two arguments (which has been there since version 1.4).

Maybe you were using the deprecated version?
 
 
subject: Special charecters in URL