Alternatively, you could use this syntax...
<html>
<head>
<base href="<%= request.getContextPath() %>" />
</head>
<body>
<a href="file.jsp">click</a>
</body>
In general, the servlet engine automatically maps the directory name to the
application, but references to URLs from standard HTML tags are not
automatically mapped. When the <base href> tag is used, all relative URLs are
resolved relative to this value. If your application is mapped to the directory
"myapp", then in the example above the href would reference "/myapp/file.jsp".
Mike
Kevin Duffey wrote:
> I think your ok..but I use the request.getContextPath() in a "included"
> header file on all my JSP pages. I assign it to a contextPath string var and
> use it in all my href tags <a href="<%= contextPath
> %>/path/file.jsp">click</a>
>
> But, I believe the spec allows relative paths to the root of the web app.
> So, if your root is /, and the dir is i3-web, and you have a linke to
> /path/page.jsp, it would be from /i3-web/path/page.jsp.
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Kurt Hoyt
> > Sent: Thursday, August 31, 2000 7:31 PM
> > To: Orion-Interest
> > Subject: URLs in web apps
> >
> >
> > I've noticed an inconsistency in how URLs are used within the
> > servlet engine
> > in Orion. Perhaps I've never had to deal with this since this is the first
> > servlet engine I've used that supports .war files, server.xml, web.xml
> > files, etc.
> >
> > I have a web app that is deployed like this:
> >
> > server.xml contains this line:
> > <application name="i3" path="../i3"/>
> >
> > default-web-site.xml contains this line:
> > <web-app application="i3" name="i3-web" root="/i3"/>
> >
> > application.xml contains these lines:
> > </module>
> > <web>
> > <web-uri>i3-web</web-uri>
> > <context-root>/</context-root>
> > </web>
> > </module>
> >
> > I expect that absolute URLs used anywhere in my JSPs (and that includes <a
> > href="..">, <%@ include file="..." %>, and response.sendRedirect() calls)
> > would look like this /i3/<rest of URL>. However, I've noticed that for
> > anything other than <a href="..."> tags, the /i3 is implied and all I need
> > is /<rest of URL> for absolute paths.
> >
> > I have two questions:
> > 1. What does the context-root element do? The servlet and JSP specs are
> > pretty vague about this.
> >
> > 2. Should I be calling request.getContextPath() and using it to create
> > absolute URLs for <a href="..."> tags or just try and use relative URLs
> > within the <a href="..."> tags?
> >
> > Kurt in Atlanta
> >
--
//////////////////////////////////////////////////////
//
// Mike Clark
//
// Clarkware Consulting
// Enterprise Java Architecture, Design, Development
//
// http://www.clarkware.com
// [EMAIL PROTECTED]
// +1.720.851.2014
//