This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem with getResource() method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem with getResource() method." Watch "Problem with getResource() method." New topic

Problem with getResource() method.

Haiyao He

Joined: Jun 19, 2002
Posts: 1
I wonder if anyone has come across this problem in Manning's book. In listing 4.8 on p53, the line
URL url = context.getResource("files/test");
doesn't work quite well. In fact, you have to add a "/" before "files/test" to make it work.
Another problem is that by this way, it will always download the jar file by the name of the servlet itself. If you want to specify the name of the download file, you have to add another line:
res.setHeader("content-disposition", "attachment;filename=test.jar");
after line:
Can anyone tell me the difference between:
Thanks a lot.

Haiyao He
Dominic Paquette
Ranch Hand

Joined: Dec 13, 2002
Posts: 64
ServetContext.getResource(String path)
The api says that path must start with a slash so it's probably just a type o.
Your other question, I can't answer
I agree. Here's the link:
subject: Problem with getResource() method.
Similar Threads
Cannot open PDF directly, save works
Files upload problem with .dbf and .exe files
Unable to dowload the Servlet 2.4 specs.
Downloading PDF files
Downloading from JSP