http - how to download a file using a java program file that is uploaded in a website -
i have written java program httprequest
using httpurlconnection
download/upload file of format(xml
, image, documents) specific server using it's authentication api-key
. program works fine. need upload java
program file in website cloud service , need able download file server using java program file uploaded website. how can it? 1 thing make sure java
program wrote not web application, java
program.
for downloading file create function follows:
private void exportexcel(httpservletresponse response, hssfworkbook workbook) throws cpaserviceexception{ try{ response.reset(); response.setcontenttype("application/vnd.ms-excel"); response.setheader("content-disposition", "attachment;filename=" + workbook.getsheetat(0).getsheetname()+".xls"); workbook.write(response.getoutputstream()); }catch(ioexception e){ throw new cpaserviceexception(cpaconstants.application_general_error); } }
then call function as:
@requestmapping(value = "/"+controllerpaths.get_excel_for_common_process_system_report, method = requestmethod.get) @responsestatus(httpstatus.ok) public void getexcelforcommonprocesssystemreport(httpservletrequest request, httpservletresponse response, cpareportfilterdto filterdto) throws exception{ exportexcel(response, reportservice.generateexcelforreport(filterdto)); }
the above code sample one. can similar way download document form browser.
Comments
Post a Comment