• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Code to download Jar - HFJS

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, Thanks for info Frits
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this:

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was also facing the same issue. 'response.setHeader( "Content-Disposition", "attachment; filename=javaQuery.jar" )' - this line worked for me and I am now able to download jar instead of *.do file, I don't know how it works though.
reply
    Bookmark Topic Watch Topic
  • New Topic