1

I want to get value after # sign from URL address in jsp

http://www.example.com/testsite/sative.do?runninginformation=11-1970-1#11197011201240649438FT

How can I get it using query string?

Ravi
  • 30,829
  • 42
  • 119
  • 173
muhammadanish
  • 437
  • 2
  • 6
  • 20
  • yes @RohitJain complete string after# sign using query string or some other way, actually i want to highlight table row after getting that string in jsp – muhammadanish Dec 18 '12 at 12:07
  • @Danish.. Well, you have already got the answer. Use the first answer. – Rohit Jain Dec 18 '12 at 12:07
  • @RohitJain when i get the page url using: String completeUrl = request.getRequestURL().toString() + "" + request.getQueryString();, i never get the after # value in completeUrl String – muhammadanish Dec 18 '12 at 12:09
  • @RohitJain did u get my point – muhammadanish Dec 18 '12 at 12:11
  • [This link](http://www.coderanch.com/t/360089/Servlets/java/text-request) and [This post](http://stackoverflow.com/questions/2860718/how-to-get-the-request-url-from-httpservletrequest) may interest you. – Rohit Jain Dec 18 '12 at 12:14
  • In all, the fragment part is something that is for client side only. Server side has nothing to do with it. So, you can't get it from `HttpRequest` object. – Rohit Jain Dec 18 '12 at 12:16

4 Answers4

3

Try

String url = "http://www.example.com/testsite/sative.do?runninginformation=11-1970-1#11197011201240649438FT";
String f = new URI(url).getFragment();
System.out.println(f);
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1

You can use split, which will split the value into array.

String x = "hello#World";
String[] y = x.split("#");
System.out.print(y[1]);
Ravi
  • 30,829
  • 42
  • 119
  • 173
1

how about:

"http://www.example.com/testsite/sative.do?runninginformation=11-1970-1#11197011201240649438FT".replaceAll(".*#","");

this will return 11197011201240649438FT

Kent
  • 189,393
  • 32
  • 233
  • 301
1

You can't. The value after the pound-sign (#) is never sent to the server.

You will need to do some javascript processing. Basically add an onclick-handler for each link, parse the URL of the link and extract the hash-portion and add it as a regular parameter instead.

pap
  • 27,064
  • 6
  • 41
  • 46