ParamQuery grid support forum

General Category => Help for ParamQuery Grid (free version) => Topic started by: shivramkumar1308 on January 18, 2017, 09:14:50 am

Title: Need help with Excel export for struts 1.1
Post by: shivramkumar1308 on January 18, 2017, 09:14:50 am
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
Title: Re: Need help with Excel export for struts 1.1
Post by: shivramkumar1308 on January 18, 2017, 09:17:00 am
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.

Title: Re: Need help with Excel export for struts 1.1
Post by: paramvir on January 18, 2017, 02:29:36 pm
You need to map urls to actions.

http://paramquery.com/demos/export
Title: Re: Need help with Excel export for struts 1.1
Post by: shivramkumar1308 on January 18, 2017, 02:48:36 pm
 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.
Title: Re: Need help with Excel export for struts 1.1
Post by: paramvir on January 19, 2017, 10:15:05 am
That's for client side url.

Anyway what error do you get in the browser console? Debugging your code and resolving errors ( if any ) is indispensable to make it work.