File download using Java, Struts 2 and AJAX -


I want to download the file using java, struts2 and ajax.

Click on a button named "Export" on my HTML page on which AJAX will be executed which executes the query and will use the code to create .xls file and I store that file on the user's hard drive Want to download without doing it

Does anybody know how to use struts2 and AJAX in Java?

Is there an example available?

Tell me if you need more information from me ...

Thank you.

amar4kintu

You will not have to use AJAX in this case. Simply submit the form to your button in your strokes action, and use the type in action.

Example:

XML in your strokes:

  & lt; Name of the result = "download" type = "stream" & gt; & Lt; Param name = "contentdisposition" & gt; Attachments; Filename = report.xls & lt; / Param & gt; & Lt; Param name = "contentType" & gt; Application / vnd.ms-excel & lt; / Param & gt; & Lt; Param name = "input name" & gt; Inputstream & lt; / Param & gt; & Lt; Param name = "buffer size" & gt; 1024 & lt; / Param & gt; & Lt; / Results & gt;  

Your action will then provide a public input stream received inputstream () to provide data.

I think that to generate Excel files that are the library (?) Output to an arbitrary outputstream . Can write in

A faster way to convert an InputStream to Code>:

  // For example using the workbook from Apache POI ... Workbook wb; // ... bytereon output speed boss = new byteoutputstream (); Wb.write (boss); InputStream bis = new bytereinputstream (boss to bettere ());  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -