aspose file tools*
The moose likes Servlets and the fly likes request.getURL() and request.getURI() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getURL() and request.getURI()" Watch "request.getURL() and request.getURI()" New topic
Author

request.getURL() and request.getURI()

ravinderSingh singh
Ranch Hand

Joined: Nov 18, 2004
Posts: 41
Hi,

Could anyone explain to me what the difference is between the request.getURI() and request.getURL() methods?

I'm not entirely sure what the difference is between a uri and url?

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by ravinderSingh singh:
Hi,

Could anyone explain to me what the difference is between the request.getURI() and request.getURL() methods?

Thanks


I can do better than that. I can point you right to where I would go to find this out:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html

There is a detailed description of what each method does on that page.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mishra Anshu
Ranch Hand

Joined: Sep 16, 2003
Posts: 224
As per the documentation :--

getRequestURI
public String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example: 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


To reconstruct an URL with a scheme and host, use getRequestURL.

Returns
a String containing the part of the URL from the protocol name up to the query string

getRequestURL
public StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.

This method is useful for creating redirect messages and for reporting errors.

Returns
a StringBuffer object containing the reconstructed URL
getRequestURIgetRequestURL


"Ignorance is bliss"
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: request.getURL() and request.getURI()