• Post Reply Bookmark Topic Watch Topic
  • New Topic

File download button on a jsp page that does the download without taking you to another page.

 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

First of all, I'm not sure whether I should have posted this question in struts or in jsp forum as I'm not aware if it is something that can/should be handled with jsp and scriptlet combination, jsp/javascript combination or if struts has a cool tag library that can handle file download. Could you please move the topic to appropriate forum depending on where it'd better be.

My webpage needs to have a button that lets the user download a sample file from the server. And it needs to have a button that lets the user upload such a file with data. The upload part is working fine. It's the download that I'm having trouble with. This is how the upload part is working.

My form has a FormFile type field which is set in the jsp as follows.


My struts-config is as follows.

Relevant part in tiles-defs is as follows.



My form class doesn't need run any grand logic or something to do the upload. It just has the following import.

and has the usual setter for a FormFile type variable as follows.



And my action method invokes this setter. And there is no other logic I need write for the upload to work.

Isn't there something like FormFile that struts already has for the download to also work? Is there a link or a tutorial I could read?

I checked on web for "how to download a file from jsp" and almost everyone uses an tag and then creates the download.jsp that has a big scriptlet code that creates an output stream. I've tried this. When I click on the link, my page changes. This is not what I want. Plus the downloading does not happen ( but I will resolve this part later ). And the existing jsps don't use grand scriptlets so I am not sure if it's a good practice to embed lot of Java code within a JSP.

Doesn't struts have some elegant way for the download too?
Sorry if I didn't specify something that is required. I'm very new to the UI components. So I don't know much. Let me know if I need to provide more information.

I'm fine with trying out anything that's available- tutorials, links, books, hints, .. so long as I can get it working in the end.

Thanks.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, the editor won't let me type the "<a href" tag correctly.
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you post, look below the box where you are typing and you'll see there are some checkboxes. Since you want to type HTML, you'll want to check the "Disable HTML in this message" checkbox. If you don't, then the forum software will attempt to evaluate the HTML you entered rather than just echoing it.

I edited your other posts and checked that box.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Paul. I'll keep that in mind.

Update: I'm going to be trying this tomorrow. Have found a couple of helpful links..
Hopefully one of those options will work.

I will keep this thread updated with whatever status I have tomorrow.

Thanks.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is resolved. Sorry I couldn't update this thread earlier than this.

What I did is this. Created a row in the jsp with a button as follows.

<tr>
<td class="formLabel"><label for="file">Download File:</label></td>
<td>
<span>
<a class="buttonStyle" href="importSomething.do?method=downLoadSampleCSV">Download Sample CSV</a>
</span>
</td>
<tr>

And added following code in the action class.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!