• 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

error in downloading file

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is a code for downloading jar file


here is the web.xml file


first i compile the ShowHeadersServlet class and put it to the
C:\Tomcat\apache-tomcat-6.0.18\webapps\hellow\WEB-INF\classes.
then i start the tomcat server.
then go to browser and type this.

http://localhost:8080/hellow/A
it downloading some file named A. But it is not a file which i need.
Actually downloaded file name is equal to the last name of the URl which i typed in browser.
i need to download the bootstrap.jar file.
Also I put this jar to the bin director in tomcat.
What is wrong with this code ?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the Content-Disposition header...
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no, i don't need a hiperlink in the broser.
I need to download the file when i put the relavant URl in browser.
The problem is that it download the file which is not expected and the name of the file is last name of URL.

if the URL type is http://localhost:8080/hellow/HelloWorldServlet
downloaded file name is HelloWorldServlet

if the URL type is http://localhost:8080/hellow/A
downloaded file name is A(I change the web.xml also to a when i chang the URL)

I check the size of the downloaded file with my expected bootstrap.jar.
bootstrap.jar size is 17.1 KB
downloaded file size is 70.4 KB.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all I didn't say that you need a hyperlink. You need to set the content-disposition header in the servlet whose code you just showed. Also where is your jar file actually located?? You are using only the jar name in the File class constructor. You should try to use the inbuilt mechanism in servlets like getResourceAsStream to read files from web application's directory. Read this thread or a tutorial like this for more info...
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i put that jar file to the tomcat/bin folder.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a web app, relative paths (like "bootstrap.jar") don't work, because there is no notion of a default directory. You need to use an absolute path - the "ServletContext.getRealPath" method will be helpful for that.
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic