• 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

File downlaod link concatenates html to file

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use the following code that is at the beginning of my jsp to activate the download dialog box on my jsp I have this one page that will allow file downloads without having to go to another page:

Then I have several links displayed:
[code]
< a class="a" href="main.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a>
[code]
I know this isnt a secure way of doing this but I am on a intranet.
The problem I am having now is that when I click on one of the links and download the file and then open it, I get the contents of the file plus concatenated to the end of it is the first few HTML lines of the actual jsp that I downloaded the file from. Before I was just getting the first few lines of html from the jsp, not the actual contents of the downloaded file.
This is an example of what I am getting note this is the actual contents of a text file I download from my app:
This is the contents of the file that I downloaded.//This is where the file contents ends.
This is where the html code is appended.

Any ideas?
TIA!
BTW, I went to ApacheJServ because they wont let me use tomcat
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there HTML content after the code you displayed above? If so, yeah it's just gonna get streamed out after your file.
JSP is a poor technology choice for this type of function. You'd be best served to move this code to a servlet.
bear
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at what the implicit "out" is in a JSP - it is a JspWriter!
When you write the value that the file read reads through a Writer, it will perform some sort of character conversion according to what the writer thinks the character set is - this is unlikely to be what you want it to be.
Therefore, like Bear says, do this in a servlet where you have total control.
Bill
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic