File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Tomcat 6 : RequestParameter value gets cut off at hash (#) character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 6 : RequestParameter value gets cut off at hash (#) character " Watch "Tomcat 6 : RequestParameter value gets cut off at hash (#) character " New topic
Author

Tomcat 6 : RequestParameter value gets cut off at hash (#) character

Edwin Rivera
Greenhorn

Joined: Mar 02, 2012
Posts: 3
Hello,

This is probably an easy one for you.

In my servlet, I am trying to capture the value of a parameter:

paramName=key
paramValue=val#ue

However, as you can see, the value contains a '#' char in the string, and, when i call request.getParameter("key"), all I get is the string "val"

How can I capture the entire string "val#ue"?

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

The "#" character has a specific meaning in URLs. So if you want to treat it as an ordinary character, you have to URL-escape it.

However it's not your servlet which has to do the URL-escaping, it's whoever generated the request in the first place. Perhaps somebody clicked on a link which you generated, which had that "#" character in it? If that's the case then you should URL-escape the parameter values when you generate that link. Anyway the first thing to do is to find out where that request came from and how the URL was generated there.
Edwin Rivera
Greenhorn

Joined: Mar 02, 2012
Posts: 3
Paul Clapham wrote: Anyway the first thing to do is to find out where that request came from and how the URL was generated there.


Therein lies the issue.

The request originates from Facebook.

This issue is happening in the servlet that is defined as the redirect_uri in our facebook oauth dialog. When a user successfully authenticates, facebook looks up the request_uri (my servlet), and issues a GET request.

The string with the '#' in it, is what is contained in the code=xxx key/value pair of the request. I need this code to then grab an access_token for subsequent Oauth calls.

Actually, *anything* after the '#' (uri fragment) is ignored by the request, even additional key/value pairs.

I'll try taking this up with FB directly if there's no easy workaround via Tomcat and the HttpRequest object.

Thanks for the quick reply!

Edwin Rivera
Greenhorn

Joined: Mar 02, 2012
Posts: 3
Looks like I'm not alone:

https://developers.facebook.com/blog/post/552/

and

http://bugs.developers.facebook.net/show_bug.cgi?id=20504

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat 6 : RequestParameter value gets cut off at hash (#) character