Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - shivramkumar1308

Pages: [1]
1
 redirectURL='<%=request.getContextPath()%>'+'/ExcelAction.do?type=excel';


This is the code that I have written to map the url to the action but it does not work.
Any pointers would be appreciated.

2
Forgot to add that I am unable to download the excel using the above code. Can someone let me know where I am going wrong.


3
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

Pages: [1]