This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes downloading a File in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "downloading a File in Struts 2" Watch "downloading a File in Struts 2" New topic
Author

downloading a File in Struts 2

Neeraj jain
Ranch Hand

Joined: Jun 18, 2013
Posts: 98
I am trying to download a file with Struts2 but when i click on the hyperlink to download the file i am getting
No result defined for action com.mkyong.common.action.DownloadAction and result success

here is the code
struts.xml


downloadPage.jsp



DownloadAction




Anyone please help me why the file isn't downloading
Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 90
You have missed mapping "download" action in struts.xml file.
Hence it isn't able to download it. Hope this helps.

Thanks,
Ashwini Kashyap | www.infocepts.com
Neeraj jain
Ranch Hand

Joined: Jun 18, 2013
Posts: 98
thanks bro but i am returning success from execute method so why i have to do the mapping of download
Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 90
i am returning success from execute method so why i have to do the mapping of download


Success will get executed only when your "download" action class will get called and you haven't mapped that action and hence it wont go into your class and execute further.

Your code should be like -

<action name="download" class=".....">
<result name="success" type="stream">
.......

instead of
<action name="success" class=".....">
<result name="success" type="stream">
.......


Regards,
Ashwini
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: downloading a File in Struts 2