tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Weigen Liang <weigenli...@yahoo.com>
Subject Re: building URL's?
Date Thu, 14 Dec 2000 14:25:23 GMT
The tomcat source codes (URLUtil.java and
SessionUtil.java) may give you some clue.

Weigen

--- Jacob Kjome <Jacob.R.Kjome@syntegra.com> wrote:
> 
> What is the best way to build URL's without
> hardcoding them?
> 
> Right now, I have tried this:
> 
> SERVLET_HOME = request.getScheme() + "://" +
> request.getServerName() +
> ":" + request.getServerPort() +
> request.getRequestURI();
> 
> DOCUMENTS_HOME = request.getScheme() + "://" +
> request.getServerName() +
> ":" + request.getServerPort() +
> request.getContextPath() + "/";
> 
> 
> This seems to work with a servlet that does posting,
> but I'm confused by
> what is said of getRequestURI() in the servlet API:
> 
> *****begin excerpt******
> 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.
> 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  
> http://foo.bar/a.html  
> HEAD /xyz?a=b HTTP/1.1  /xyz  
> 
> To reconstruct an URL with a scheme and host, use
>
HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest).
> 
> Returns:
> a String containing the part of the URL from the
> protocol name up to the
> query string
> *****end excerpt*******
> 
> 
> It seems to say that it should return the whole
> path, whereas I am
> already specifying that from the scheme all the way
> up to the server
> port.  I need to get the the context + path info
> (such as /servlet/) and
> the actual servlet.
> 
> Another problem with what I'm doing is that
> getContextPath() does not
> exist in the servlet 2.1 API.
> 
> 
> So, what is the best generic (and most proper) way
> to get what I'm
> trying to achieve?
> 
> 
> thanks,
> 
> Jake


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/

Mime
View raw message