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

How to send a JAR to the browser????

 
Amit Das
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Please refer this code snippet:


I've written a code to get a JAR file whic is kept on the server side.
According to the Manning's Book for SCWCD,
if we store any resource (here it's the .jar file) in the bin directory of Tomcat and we write


it will create a file object, but when I'm writing the code as the author
says, I get a a Runtime Exception
"java.io.FileNotFoundException: test.jar (The system cannot find the
file specified)"


1.So Is the author wrong in saying this, that File object is created if we
just give the file name in the constructor of File and keep the file in
the bin folder of Tomcat?

2. Now as u can see in my code; I'm creating the File object by giving the
absolute path of file. If I try to access this servlet from the browser,
instead of getting the file to download, I get as decoded on the browser,
which is not as the author says it should. The author says...
"If we want to send a binary file, for example a JAR file, to the client.."

It means it will be sent as file only, but when i try the code, there is
a different behavior. CAn anyone explain??

But again if i use ServletContext.getResourseAsStream(String path) (plz
use the commented code by uncommenting it and comment the previously
uncommented code) I get the file as downloadable.

Run the code and answer, if possible.

Thanks,
Amit
 
Amit Das
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone look into this and answer please.

Regards,
Amit
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can get a simpler version of the code in HFSJ chapter 4 or 5
 
Amit Das
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok can u tell me if you put some file in Tomcat bin folder, can we access
it like this--------------->

File f = new File("<file-name>"); ???

P.S: file-name can be sth like test.jar

Regards,
Amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic