I am using struts to develop my web application. I wrote a method which generates excel file and saves it based on the data model I pass.. Works great on my local machine since tomcat is present locally.. But now I’ve moved my application to a central server.. Now if I use the method it stores generates the excel file in the server not in the client machine which are hitting the server.. I need to pass it from server to client through http.. How do I do that?
public static void populateExcelDoc(List<ColumnList> listOfColumns,RowList rowlist,String filename)
{
try
{
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename+".xls"), ws);
WritableSheet s = workbook.createSheet("Sheet1", 1);
writeDataSheetifx1(s,listOfColumns,rowlist);
workbook.write();
workbook.close();
Process p =
Runtime.getRuntime()
.exec("rundll32 url.dll,FileProtocolHandler " + filename+".xls");
}
catch(IOException e)
{
e.printStackTrace();
}
catch(WriteException e)
{
e.printStackTrace();
}
}
This is what my current code looks like.. What change do I need to make? Should I be using HttpServletResponse response?
In Struts2 there is
streamresult for sending data to the HttpServletResponse.In your
struts.xmlconfigure your action to usestreamresult.And inside your action create
private InputStream inputStream;with getters/setters and write your file to it inside your method.