Summary: | Context relative URLs returned by ServletContext.getResource() for the same path are not equal | ||
---|---|---|---|
Product: | Tomcat 5 | Reporter: | Jan Luehe <jan.luehe> |
Component: | Catalina | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | Nightly Build | ||
Target Milestone: | --- | ||
Hardware: | Other | ||
OS: | other |
Description
Jan Luehe
2005-09-07 04:52:04 UTC
I will not be fixing that, as this changes the value of toString for the URL. Good point about toString(). I have a solution for that as well. Just override org.apache.naming.resources.DirContextURLStreamHandler.toExternalForm() and have it ignore the "authority" part of the URL, as follows (this is copied from java.net.URLStreamHandler.toExternalForm(), with "authority" part ignored): /** * Converts a <code>URL</code> of a specific protocol to a * <code>String</code>. * * @param u the URL. * @return a string representation of the <code>URL</code> argument. */ protected String toExternalForm(URL u) { // pre-compute length of StringBuffer int len = u.getProtocol().length() + 1; if (u.getPath() != null) { len += u.getPath().length(); } if (u.getQuery() != null) { len += 1 + u.getQuery().length(); } if (u.getRef() != null) len += 1 + u.getRef().length(); StringBuffer result = new StringBuffer(len); result.append(u.getProtocol()); result.append(":"); if (u.getPath() != null) { result.append(u.getPath()); } if (u.getQuery() != null) { result.append('?'); result.append(u.getQuery()); } if (u.getRef() != null) { result.append("#"); result.append(u.getRef()); } return result.toString(); } It is important that URLs returned by ServletContext.getResource() that are equal have equals() return TRUE. This works for all other kinds of URLs. |