This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Decoded URI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Decoded URI" Watch "Decoded URI" New topic
Author

Decoded URI

Maxim Katcharov
Ranch Hand

Joined: Sep 07, 2004
Posts: 113
I'm using HttpServletRequest.getRequestURI(), because I need this simple form (from javadoc):

First line of HTTP request Returned Value
POST /some/path.html HTTP/1.1/some/path.html
GET http://foo.bar/a.html HTTP/1.0 /a.html
HEAD /xyz?a=b HTTP/1.1/xyz

Unfortunately, "The web container does not decode this String", which leaves me with things like /foo%20bar.html when I call it.

I need a clean way to decode the URI that is returned (or to convert the returned value of getRequestURL into the 'simple' form above).

Does anyone have any ideas?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
The java.net.URLDecoder and URLEncoder classes handle this.


Ping & DNS - updated with new look and Ping home screen widget
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Maxim Katcharov:
First line of HTTP request Returned Value
POST /some/path.html HTTP/1.1/some/path.html
GET http://foo.bar/a.html HTTP/1.0 /a.html
HEAD /xyz?a=b HTTP/1.1/xyz

Unfortunately, "The web container does not decode this String", which leaves me with things like /foo%20bar.html when I call it.


Means you are getting "/foo%20bar.html" instead of "/a.html"??
Maxim Katcharov
Ranch Hand

Joined: Sep 07, 2004
Posts: 113
That was a lot easier than I was finding it to be, thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decoded URI
 
Similar Threads
jsp:include
getRequestURI() vs getRequestURL()
invoke a servlet without form submit button
How do I find URL after redirection?
request.getURL() and request.getURI()