This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
java.net.URL getResource(String path) method returns a java.net.URL object for the resource that is mapped to the given path. Although the path should start with / it is not an absolute path. It is relative to the document root of this web application. For instance, if you pass a path to a JSP file, it will give you the unprocessed data, i.e., in this case, the JSP source code, when you read the contents. java.lang.String getRealPath(String path) method returns a string that shows the whole real path for the given virtual path... here is the problem associated with getRealPath method, that I extracted from SCWCD Study Kit...
the problem with this approach is that it is not helpful when the resource is inside a JAR file. It is also useless when the servlet is running in a distributed environment where the resource may reside on a different machine. In such situations, the getResource() method comes handy.
Thanx a lot ... i hvae read somewhere that getReaource can not be used for the active jsp's & servlets.... What does it mean?? THANX
Ko Ko Naing
Joined: Jun 08, 2002
It means that if you pass a path to a JSP file, it will give you the JSP source code, when you read the contents.... It will not give you as the JSP-generated html page... i.e., you will the response like <html><head></head><body>Hello World!</body></html> as unprocessed data... You will not get just only Hello World! as you expect.... Hope it is clear...
Joined: Sep 28, 2003
Hey Naing .... Thanx a lot... for clearing the confusion....