In the exportExcel method, Can someone please tell me what should be the code for the url parameter for a Struts 1.1 version application.
I am using the below Java Action class.
package com.action.export
public class ExcelAction {
public String excel(String excel, String extension, HttpServletRequest request) throws IOException {
String filename="";
if (extension.equals("csv") || extension.equals("xml")) {
filename = "pqGrid." + extension;
HttpSession ses = request.getSession(true);
ses.setAttribute("excel", excel);
}
return filename;
}
public void excel(String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (filename.equals("pqGrid.csv") || filename.equals("pqGrid.xml")) {
HttpSession ses = request.getSession(true);
String excel = (String) ses.getAttribute("excel");
byte[] bytes = excel.getBytes(Charset.forName("UTF-8").toString());
response.setContentType("text/plain");
response.setHeader("Content-Disposition",
"attachment;filename=" + filename);
response.setContentLength(bytes.length);
ServletOutputStream out = response.getOutputStream();
out.write(bytes);
out.flush();
out.close();
}
}
}
In the JSP file, I am using the below code for the export function
"click": function (evt) {
var redirectURL="";
redirectURL='<%=request.getContextPath()%>'+'/ExcelAction.do?type=excel';
jQuery("#grid_table").pqGrid("exportExcel", { url: redirectURL, sheetName: "pqGrid sheet" });
}
The filepath for the JSP is WebContent/pages/TestFile.jsp