File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Have problem with getResource()! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Have problem with getResource()!" Watch "Have problem with getResource()!" New topic

Have problem with getResource()!

Eliot Skywalker

Joined: Oct 22, 2003
Posts: 18
I've got a question with ServletContext.getResource()
This method returns a object. In the servlet api document, description of this method says:
The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a RequestDispatcher instead to include results of an execution.

my question is, how can a URL "returns the JSP source code"
what does it mean?

Every man dies, not every man really lives.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Skywalker is really your last name? And you are sure you don't have a brother Luke.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The URL returned is based in what the ClassLOader can 'see'. The ClassLoader has access to Files, but nothing else. Therefore the reference to the JSP is a file url and not a http url.
I agree. Here's the link:
subject: Have problem with getResource()!
It's not a secret anymore!