Bug 22860

Summary: tag url generate invalid result for root context
Product: Taglibs Reporter: Cyril Sochor <sochor>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Cyril Sochor 2003-09-01 14:36:05 UTC
Tag URL is buggy for context "/".

<c:url context="/" value="/something.jsp"/>
this is interpreted by browser (Galleion 1.3.5) as host name, not as absolute path .

Correct result is "/something.jsp"
Comment 1 Pierre Delisle 2003-09-10 20:33:41 UTC
The 'context' attribute is to be used to specify
a *foreign* context.

From the spec:
  Name of the context when specifying a relative URL
  resource that belongs to a foreign context.

Specifying '/' does not represent a valid foreign context,
and therefore leads to the problem you're having.

If a resource belongs to the current context, attribute
context should not be used.
Comment 2 Cyril Sochor 2003-09-17 12:17:50 UTC
I hope that '/' is valid foreign context, if context-root element in
application.xml is '/'.
For example, this is my application.xml:

I need generate link from backend application to frontend application.
Applications have diferent contex, attribute 'context' of tag 'c:url' must be
There is some.jsp in hyperion-backand.war with this tag:
<c:url var="frontendLinkURL" value="/main.jsp" context="/"/>
It generate <a href="//main.jsp"/> :-(

It's bad result, because many browsers interpret this as host name, not
as absolute path at same host. Correct result is <a href="/main.jsp"/>

There is my patch:

Index: UrlSupport.java
RCS file:
retrieving revision 1.6
diff -u -r1.6 UrlSupport.java
--- UrlSupport.java     4 Aug 2003 17:44:37 -0000       1.6
+++ UrlSupport.java     2 Sep 2003 13:51:17 -0000
@@ -189,7 +189,12 @@
             if (!context.startsWith("/") || !url.startsWith("/"))
                 throw new JspTagException(
-            return (context + url);
+            if (context.equals("/")) {
+               // don't produce string starting with "//", many
interpreting this url as host name, not as absolute path on same host
+                               return url;
+            } else {
+                               return (context + url);
+            }

Comment 3 Pierre Delisle 2003-12-12 23:39:06 UTC
My bad, apologies... Just committed the fix for JSTL 1.1.
Thanks for the bug report Cyril.