aspose file tools*
The moose likes Servlets and the fly likes How to put '&' in request query string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to put Watch "How to put New topic
Author

How to put '&' in request query string

Atul Samnerkar
Ranch Hand

Joined: Sep 20, 2003
Posts: 44
Hello,

We are facing problem when we have '&' in our query string. For example http://somehost/somepage.jsp?key1=value1&key2=A&B.

Here key2 value is A&B but because & is a separator for query string, we only get A as value.

We cannot really use POST here because this is a hyperlink and not a form submit.

How can I fix this so that I can correctly get values in the target page of hyperlink on server side (somepage.jsp).

-Regards
Atul
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

You need to encode the URL. The HttpServletResponse has encodeURL() method .Ampersand is %38 if I remember correctly.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Manjusha Muraleedas
Ranch Hand

Joined: Jun 02, 2010
Posts: 52
Please post the address of any site/resource explaining this encoding technique?

I googled for "URL Encoding Technique" . but i didnt get any useful link.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

On the server use URLEncoder.encode(). On the client encodeURIComponent() oe encodeURI().


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Manjusha Muraleedas wrote:
I googled for "URL Encoding Technique" . but i didnt get any useful link.

Seriously?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

John Todd wrote:
Manjusha Muraleedas wrote:
I googled for "URL Encoding Technique" . but i didnt get any useful link.

Seriously?


Maybe he checked just the first link... O.o

Dude, i did that research and i found tons of links....

Go there and be happy.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Manjusha Muraleedas
Ranch Hand

Joined: Jun 02, 2010
Posts: 52
Sorry for wasting your time...i didnt had any idea about it... I am new to servlet world and just started studying the basics...

Thank you Bear Bibeault for the help...:-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to put '&' in request query string