aspose file tools*
The moose likes JSP and the fly likes File downlaod link concatenates html to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "File downlaod link concatenates html to file" Watch "File downlaod link concatenates html to file" New topic
Author

File downlaod link concatenates html to file

g forte
Greenhorn

Joined: Aug 28, 2003
Posts: 25
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File downlaod link concatenates html to file