Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with getResource() method.

 
Haiyao He
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
res.setContentType("application/octet-stream");
Can anyone tell me the difference between:
res.setContentType("application/octet-stream");
and
res.setContentType("application/jar");
Thanks a lot.
 
Dominic Paquette
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Dominic
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic