Bikas Katwal
Bikas Katwal

Reputation: 2035

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

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.

Upvotes: 2

Views: 3504

Answers (4)

Étienne Miret
Étienne Miret

Reputation: 6650

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

Upvotes: 2

Bikas Katwal
Bikas Katwal

Reputation: 2035

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 :)

Upvotes: 0

priyadarshini
priyadarshini

Reputation: 55

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

String url1=request.getRequestURI();

url1.split("/");

Upvotes: 0

Kuldeep Singh
Kuldeep Singh

Reputation: 45

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?

Upvotes: 1

Related Questions