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
  • 29,945
  • 41
  • 114
  • 168
muhammadanish
  • 437
  • 2
  • 6
  • 19
  • 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
  • 203,151
  • 43
  • 392
  • 509
Evgeniy Dorofeev
  • 129,181
  • 28
  • 195
  • 266
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
  • 29,945
  • 41
  • 114
  • 168
1

how about:

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

this will return 11197011201240649438FT

Kent
  • 181,427
  • 30
  • 222
  • 283
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
  • 26,156
  • 6
  • 39
  • 46