Error Caused by getservletcontext (). getresource ()
Tomcat4.1:
/**
* Return a URL object of a resource that is mapped to
* Specified context-relative path.
*
* @ Param path context-relative path of the desired Resource
*
* @ Exception malformedurlexception if the resource path is
* Not properly formed
*/
Public URL getresource (string path) throws malformedurlexception {
If (! Path. startswith ("/"))
Throw new malformedurlexception ("path'" + path +
"'Does not start '/'");
Return (new URL (myresourcebaseurl, path. substring (1 )));
}
Tomcat 5.5:
Public URL getresource (string path)
Throws malformedurlexception {
System. Out. println ("Qik:" + path );
If (Path = NULL |! Path. startswith ("/")){
Throw new malformedurlexception (Sm. getstring ("applicationcontext. requestdispatcher. IAE", PATH ));
}
Path = normalize (PATH );
If (Path = NULL)
Return (null );
String libpath = "/WEB-INF/lib /";
If (path. startswith (libpath) & (path. endswith (". Jar "))){
File jarfile = NULL;
If (context. isfilesystembased ()){
Jarfile = new file (basepath, PATH );
} Else {
Jarfile = new file (context. getworkpath (), PATH );
}
If (jarfile. exists ()){
Return jarfile. tourl ();
} Else {
Return NULL;
}
} Else {
Dircontext resources = context. getresources ();
If (resources! = NULL ){
String fullpath = context. getname () + path;
String hostname = context. getparent (). getname ();
Try {
Resources. Lookup (PATH );
Return new URL
("JNDI", "", 0, getjndiuri (hostname, fullpath ),
New dircontexturlstreamhandler (resources ));
} Catch (exception e ){
// Ignore
}
}
}
Return (null );
}
---------------------------
When using getresource, the program architecture accidentally imports a "", causing an error in running Tomcat 5, prompting path does not start "/"