wood burning stoves 2.0*
The moose likes Servlets and the fly likes Getting the value after # Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting the value after #" Watch "Getting the value after #" New topic
Author

Getting the value after #

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

I have a servlet which recieves a request with a URL something like this

www.aaa.com/page.html#22

Now I want to take out the value 22 in my servlet. Is there any way to do that???


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You can use String#split(regex) , where regex as "#" OR you can get String#substring(index) , where index as , index of "#" in string !

Hope this helps !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

No the problem is not that. Is there any way to get the full request string. I have tried request.getQueryString, request.getRequestURL, request.getRequestURI, but none of them gives me the whole request string which includes #22...
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by Ankit Garg:
I have a servlet which recieves a request with a URL something like this

www.aaa.com/page.html#22



How is your request going to server ? Whats in your action URI ? and What your are getting at Servlet using request.getRequestURL, request.getRequestURI methods ?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I think the HttpServletRequest method you want is getPathInfo()

Bill
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

getPathInfo returns the URL from the servlet mapping to the query string...

Actually my servlet also receives some query string. and the # is appended to the URL after the query string like this-

www.aa.com/page?category=1#15
[ September 30, 2008: Message edited by: Ankit Garg ]
Victor Dolirio
Ranch Hand

Joined: Aug 21, 2008
Posts: 57
the '#' character is actually used by the browsers to anchor the page, i�ve had experienced this and nothing beyond the # is submited to server so if really want get that character you must use the escape characters for URL, take a google on that .
[ September 30, 2008: Message edited by: Victor Dolirio ]

If happen something bad in you life, don't ask God why it happened. Ask for what.
SCJP 5 (80%) - SCWCD 5 (91%) - SCBCD & SCJD coming soon...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If your query string looks like:


WHY did your original post give the example:


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Originally posted by William Brogden:
If your query string looks like:




I didn't knew that it would make a difference...Sorry for that...
 
Don't get me started about those stupid light bulbs.
 
subject: Getting the value after #
 
Similar Threads
how to Get full url with # symbol in servlet?
Forwarding data after processing
calling a webpage at the click of a button
What method to use to get VALUE of the only checked radio in the current page
Poking Values into the HTTP Header