Monday, January 10, 2011

Recently I faced a issue where the URL formation was something like this : -

"http ://<server:port&gt/<context&gt/something.jsp#anchorValue"

and we were supposed to get the value of "anchorValue" from the URL.

We tried a various method exposed by the ServletRequest and its child classes: -1. getQueryString()2. getRequestURI()3. getPathInfo()4. getPathTranslated()5. getRequestURL()

But none of the above method could give us the value after "something.jsp".

It seems that "#anchorValue" was totally ignored by the server

After carefully analyzing the URL interpreted by the Browser and the URL received by the server, we found that browser itself strips of few of the characters from the URL, before it sends to the server and "#" (and its) preceding values is one such case.

"#" and the content preceded by "#", is stripped off from the URL by the browser and the rest of the URL is sent to the server for further processing

Browser understands "#" as the internal Link to an HTML document (received as a part of response from the server)

Let's assume that we have the Following URL: -

http://www.somewhere.com/something.jsp#anchorValue

And from the Above URL we want to extract the text "anchorValue".

Now the browser will send only "http://www.somewhere.com/something.jsp" to the server and "anchorValue" will be used to find and internal Link in the HTML Document which is sent by the server as a part of response.