This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getResource & getRealPath

 
Andy Smith
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the difference between the "getRealPath" and "getResource"???
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andy Smith
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Andy Smith
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Naing ....
Thanx a lot... for clearing the confusion....
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic