views:

23

answers:

4

I have a queryString that I pass to a servlet's doGet() method that looks like this:

count=9&preId0=-99&objId0=-99&preId1=-99&objId1=-99&preId2=69&objId2=16#!78&preId3=-99&objId3=-99&preId4=-99&objId4=-99&preId5=-99&objId5=-99&preId6=-99&objId6=-99&preId7=-99&objId7=-99&preId8=-99&objId8=-99

After and including the # everything is null, so I am assuming the # has some special meaning. Is this true? and are there other such characters that will do this?

+2  A: 

The # indicates the anchor portion of the URL, which is used to identify a specific position within the document returned by the rest of the URL. It technically known as the Fragment portion of the URI.

Everything following the # is part of that. Since it is only relevant once the document is returned and processed (again, it represents a position in that document) it is only interesting to the client. It has no meaning or value to the server and the client will treat the entire value as a single value (unless of course you provide additional custom code to break apart the value and extract additional meaning from it).

If you need to pass the character # as part of a value in the URL, replace it with %23 - you can do this programmatically using URL Encoding, which will replace all "special" characters with ones that are acceptable for transport via URI.

Rex M
+2  A: 

As a general rule of thumb, it's a good idea to URLENCODE your querystring parameters before you send them through to the server. The # in the url is used to represent what anchor you're currently at and will cause problems when trying to send it through to the server.

More info on URL Encoding can be found here: http://www.w3schools.com/tags/ref_urlencode.asp

lomaxx
+4  A: 

Yes, the # indicates a hash. This is used, for example, to jump to anchor tags within a page. Whenever you put data in a URL, you need to URL encode it. In JavaScript, you can use encodeURIComponent(). In other languages, you will need to lookup the documentation.

Michael Aaron Safyan
+2  A: 

"#" is a special character. It references the hash that is generally used in page anchors. You can simply encode this character %23 in the url and that will eliminate the issue. Other meaningful characters are ? [space] &

John Hartsock