1

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.

Bikas Katwal
  • 1,895
  • 1
  • 21
  • 42

4 Answers4

1

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
Étienne Miret
  • 6,448
  • 5
  • 24
  • 36
0

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?

Community
  • 1
  • 1
0

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

String url1=request.getRequestURI();

url1.split("/");
  • I guess its request.getRequestURI(), anyways not getting # value in request URI. Already mentioned in questions same. Thanks anyways – Bikas Katwal Dec 22 '16 at 12:42
  • String completeURL = requestURL.toString(); have u tried this and r u working in servlets or any other framework – priyadarshini Dec 22 '16 at 13:42
  • In servlets, found out, in request we don't get fragmented URL. Even in requestURL you just get complete URL other then fragmented URL(#part) – Bikas Katwal Dec 23 '16 at 07:39
0

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

Bikas Katwal
  • 1,895
  • 1
  • 21
  • 42