Get hash tag(#) character of URL in servlet request

3.2k views Asked by At

I have a URL abc.com/#cancel. In my servlet I need to store #cancel for future use. I have already tried HttpServletRequest getRequestURI() and few other options. But don't see this value in request object. How do I get this value.

In my application I am using GWT which uses rpc calls and rpc request is made based on the hash tag value. eg: mydomain.com/#profile, forwards the request to profile.rpc. In my case I am intercepting this call with a filter which does some basic check and then I want to forward the request again to mydomain.com/#profile. but I am not able to find #profile in request object. Hope this explains my question and what I am looking for.

4

There are 4 answers

0
Bikas Katwal On

Found out that fragmented URL doesn't come in request, when we do response.sedRedirect(), browser doesn't remove the fragmented part from browser URL bar. But not sure how this happens. Anyways in my case instead of posting request to another JSP and then submitting the form to different URL, I am directly doing response.sendRedirect(), which doesn't remove the fragmented part, so its working now :)

3
priyadarshini On

request.getRequestURI() will gives you the url eg:abc.com/#cancel.

String url1=request.getRequestURI();

url1.split("/");
0
Kuldeep Singh On

Hash(#) is used to separate fragment from Url. Fragment is an optional part of the URL and is used to address a particular part of a resource.

please see below links
http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/
URL fragment (#) allowed characters
List of valid characters for the fragment identifier in an URL?

0
Étienne Miret On

You cannot get the fragment part of a URL server side, as the browser won't send it to the server.

Eg: User click a link to http://www.example.com/foo#bar. Browser connect to www.example.com and send:

GET /foo HTTP/1.1
Host: www.example.com