firblazer — 2011-01-06T04:44:27-05:00 — #1
I need to get the value after the # sign in the url in Java.
For example: http://www.somewhere.com/something.jsp#anchorValue
How can I get "anchorValue" in Java?
rushiku — 2011-01-06T09:33:46-05:00 — #2
firblazer — 2011-01-07T01:19:20-05:00 — #3
Are you saying getting the "something.jsp#anchorValue" first then use string split?
How do I get the "something.jsp#anchorValue" in the first place?
sumit1001 — 2011-01-07T02:32:14-05:00 — #4
something like this: -
String str = "http://www.somewhere.com/something.jsp#anchorValue";
String str1 = str.split ("#");
firblazer — 2011-01-07T04:06:06-05:00 — #5
I need to get it from the url. I have tried request.getContextPath(), request.getURI(), request.getURL()...etc. but with no success. It doesn't give me the value after the #.
Please help. Thanks.
sumit1001 — 2011-01-07T04:13:35-05:00 — #6
firblazer — 2011-01-07T04:15:32-05:00 — #7
Tried. Doesn't give the value after the #.
sumit1001 — 2011-01-07T04:19:57-05:00 — #8
if i understand correctly you are hitting the browser with this URL
if yes than where are you getting the value of request.getRequestURI()
And also can you try if getQueryString() returns "anchorValue"?
firblazer — 2011-01-07T04:21:46-05:00 — #9
Yes, you are right. But getQueryString() returns a null.
sumit1001 — 2011-01-07T05:27:13-05:00 — #10
Here is the problem: -
whenever you type the above URL in the browser, the browser searches for the exact path typed in the URL till the time it reaches the extension which it recognizes and as soon it encounters an executable extension it tries to execute that (in your case it it something.jsp).
After processing the executable extension the first character it recognize is the "?" and after that you can give any number of parameter.
Note: the URL doesn't accepts any special characters (apart from "/"), for e.g. type the below URL
In this case you will still see the output of something.jsp on the Browser.
If you really need to execute your URL than either replace "#" with "?"
remove the .jsp from the recognized extensions and use "/" instead of "#" and create a servlet which interprets the request and forward it to desirable URL.
sumit1001 — 2011-01-10T07:51:55-05:00 — #11
I debugged it further and found that my earlier explanation is not correct.
"#" and the content preceding "#", is stripped off from the URL by the browser and the rest of the URL is sent to the server for further processing
Browser understands "#" as the internal Link to an HTML document (received as a part of response from the server)
from the above URL browser will send only "http://www.somewhere.com/something.jsp" to the server and "anchorValue" will be used to find and internal Link in the HTML Document which is sent by the server as a part of response.
Refer this Internal Links in a HTML
You cannot use browser and java to process "#" and its value.
Although JS can be used to find the complete URL including the value.