public String getRootURL(String requestURI, String servletPath) {
                rootURL = requestURI.substring(0,requestURI.indexOf(servletPath));
                return rootURL;
        }

Calling Request.getURI() from a servlet at:
http://www.mydomain.com/myapp/servlet/TestServlet returns
"/myapp/servlet/TestServlet"

Calling Request.getServletPath() from a servlet at:
http://www.mydomain.com/myapp/servlet/TestServlet returns
"/servlet/TestServlet"

Using the function above will return: "/myapp" as the root url.
Now you can use: "<img src=" + rootURL + "/pathToImage/img.gif>"

--------------------
Kevin Baynes
Software Engineer
Seagull Software


> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of ARPON
> Mart�n DST
> Sent: Wednesday, August 29, 2001 3:20 PM
> To: [EMAIL PROTECTED]
> Subject: Re: WebApp mapping
>
>
> Thanks for the quick answwer but getRealPath()
> is not what I 'm looking for. getRealPath() would
> give me, for example, "c:\data\...\..."
>
> Suppose I have the class TestServlet, that is
> called with http://www.mydomain.com/myapp/servlet/TestServlet
>
> Inside doGet() I want to return an html page
> with a link to a gif that 's located in
> http://www.mydomain.com/myapp/img/test.jpg";.
>
> If I use relative paths, I can use "../img/test.jpg",
> but if I want to use absolute paths (what I want),
> I must send to the client "/myapp/img/test.jpg".
>
> Instead of "/myapp/" directly in code, I want
> to do it dynamically, so tomorrow I can map
> the application to an other point and don 't
> break it.
>
> I found getServletContextName() in spec 2.3 but
> nothing in 2.2.
>
> Any ideas ?
>
>
> -----Original Message-----
> From: PUB: Lindsay, William (USPC.PCT.Hopewell)
> [mailto:[EMAIL PROTECTED]]
> Sent: Mi�rcoles, 29 de Agosto de 2001 04:04 p.m.
> To: [EMAIL PROTECTED]
> Subject: Re: WebApp mapping
>
>
> I believe this what you are looking for.
>
> System.out.println(getServletContext().getRealPath("http://www.myd
> omain.com/
> myapp"));
>
> -----Original Message-----
> From: ARPON Mart�n DST [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 29, 2001 2:46 PM
> To: [EMAIL PROTECTED]
> Subject: WebApp mapping
>
>
> Hi, how can I know what path is my webapp
> mapped to ?
>
> I mean, if I use http://www.mydomain.com/myapp
> to access the application, where how can I
> obtain in servlet code the "myapp" value ?
>
> Thanks,
>
> Martin
>
> __________________________________________________________________
> _________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> __________________________________________________________________
> _________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> __________________________________________________________________
> _________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to