• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Code to download Jar - HFJS

 
Vishal Kukreja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying below code from HFJS Chap-4, where client get Jar file on click of download.

Here problem is, when I click on Download button, it opens save dialog box with file name as of servlet name(selectCoffee.do) instead of javaQuery.jar.

HTML code:


Servlet code:


File javaQuery.jar is located under webapps\ResponseJar

Please help!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2343
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishal,

How does you web.xml look like? What is the structure of your .war file?

Regards,
Frits
 
Vishal Kukreja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits,

below is the code in web.xml


and directory structure of this webapp is

Tomcat_HOME
--\webapps\ResponseDemo\javaQuery.jar -- file for download
--\webapps\ResponseDemo\WEB-INF\web.xml --DD
--\webapps\ResponseDemo\WEB-INF\classes\com\example\web\CoffeeSelect.class --servlet class

and I'm directly trying to run it with
http://localhost:8080/ResponseDemo/selectCoffee.do
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2343
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, everything looks fine.

Just change the .do into .jar and you will see that it works. (after saving open the file in winzip or similar program)

Regards,
Frits
 
Vishal Kukreja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits,
It works.

Can you please tell me instead of file name as javaQuery.jar why it is prompting to save as servlet name.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2343
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell me instead of file name as javaQuery.jar why it is prompting to save as servlet name.

It is actually prompting to save the selectCoffee.do because of the servlet mapping. The browser only knows that you are doing a GET request to the URL http://localhost:8080/ResponseDemo/selectCoffee.do and sees that it is returning a file (because of the content-type). The browser has no knowledge of the fact that the Servlet in the web-container is actually returning a .jar file.

Regards,
Frits
 
Vishal Kukreja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, Thanks for info Frits
 
jalil idrissi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic