File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 41101
    
  45
The java.net.URLDecoder and URLEncoder classes handle this.


Ping & DNS - my free Android networking tools app
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.
 
Consider Paul's rocket mass heater.
 
subject: Decoded URI
 
Similar Threads
request.getURL() and request.getURI()
jsp:include
How do I find URL after redirection?
getRequestURI() vs getRequestURL()
invoke a servlet without form submit button