This is simply a matter of your context path being "/" or being something like "/mycontext". With the former, as long as you aren't one or more directories deep into your webapp, then using "script/utility.js" and "/script/utility.js" are completely equivalent. However, if you are a couple directories deep then the first one will be invalid and if you are using the "/mycontext" path, then the second one will be invalid. The solution is to either always use relative paths and account for directory levels or always use paths based off the root of the web, but make sure to prefix the servlet context path such as...

this.getContextPath() + "/script/utility.js"

Dynamically adding the context path this way guarantees that no matter what context path your webapp is deployed in, the path to your file will always be valid.

See:
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletRequest.html#getContextPath()

Jake

At 07:39 PM 12/29/2003 +0800, you wrote:
Howdy,

I am developing a web app using win2k pro + Tomcat

In a servlet , the following code works ( file /script/utility.js can be get by IE)

sb.append ("<html>\n");
sb.append ("<head>\n");
sb.append ( getContentTypeMeta(_req) );
sb.append ("<script language=javascript1.2 src=\"/script/utility.js\"></script>\n");


^
but when the preceding slash is deleted,  IE can not get the js fileļ¼š

sb.append ("<html>\n");
sb.append ("<head>\n");
sb.append ( getContentTypeMeta(_req) );
sb.append ("<script language=javascript1.2 src=\"script/utility.js\"></script>\n");


^ no / here

BTW, both are OK under TC 4.0.1.
Because the web app will be deployed in another servlet container which only
recognize the first format , I want to using the format with preceding "/ " , how should I do ?
( better not to use 4.0.1 :)


TIA




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to