How to export data to Excel form a portlet? - Websphere

This is a discussion on How to export data to Excel form a portlet? - Websphere ; Hi: my problem is from my portlet application i get data from database, the JSP show as following table: Order id | Name | IC |Contact No. 1000 |wang |g100|0122326182 1000 |wang |g100|0122326182 1000 |wang |g100|0122326182 1000 |wang |g100|0122326182 i ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: How to export data to Excel form a portlet?

  1. How to export data to Excel form a portlet?

    Hi:

    my problem is from my portlet application i get data from database, the JSP show as following table:


    Order id | Name | IC |Contact No.


    1000 |wang |g100|0122326182

    1000 |wang |g100|0122326182

    1000 |wang |g100|0122326182

    1000 |wang |g100|0122326182




    i need a button to export the data to Excel file.



    i am already read all the related post in this forums, from http://www-128.ibm.com/developerwork...&#13987685

    i got some ideas to using a servelet to process the data,when i try to depoly it into my code,it not working, from the JSP page i can not call the serverlet using the code :

    input type="button" value="Export Into Excel" onclick= "location.href='




    is there anybody know how to solve the problem? and are there need some confige inside the portlet.xml or web.xml?



    If possible can you show me some code for how to access it, thanks!



    Online waiting your reply!!

  2. Re: How to export data to Excel form a portlet?

    well you need to define the servlet in the web.xml have you done that?



    IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

    IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0



    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

  3. Re: How to export data to Excel form a portlet?

    i am using the following way it working..

    PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/ExportExcelServlet")

    rd.include(request,response);

    but from the JSP page can not call the servlet..


    the following coding is my servlet, when inside the servlet,

    * response.setContentType("application/vnd.ms-excel");*

    this line hit error....


    public class ExportExcelServlet extends HttpServlet {



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

    {

    // TODO Auto-generated method stub

    String filename = "WebPortInSummaryReport";

    String data = "";

    data=getData(request);

    response.reset();

    * response.setContentType("application/vnd.ms-excel");*

    response.setHeader("Content-Disposition", "attachment;filename=Device.xls");

    response.setHeader("Content-Disposition", "attachment; filename=" + filename + ".csv");

    ServletOutputStream op;



    try

    {

    op = response.getOutputStream();

    op.write(data.getBytes());

    op.close();

    }

    catch (IOException e)

    {

    //TODO Auto-generated catch block

    e.printStackTrace();

    }

    }


    the error message as follow:



    6/26/08 19:33:00:279 SGT 00000052 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet ExportExcelServlet. Exception thrown : java.lang.IllegalArgumentException: application/vnd.ms-excel

    at org.apache.pluto.core.impl.RenderResponseImpl.setC ontentType(RenderResponseImpl.java:152)

    at javax.servlet.ServletResponseWrapper.setContentTyp e(ServletResponseWrapper.java(Compiled Code))

    at webmnpportinsummaryreport.ExportExcelServlet.doGet (ExportExcelServlet.java:29)

    at javax.servlet.http.HttpServlet.service(HttpServlet .java:743)

    at javax.servlet.http.HttpServlet.service(HttpServlet .java(Compiled Code))

    .....



    6/26/08 19:33:00:544 SGT 00000052 ServletWrappe E SRVE0014E: Uncaught service() exception root cause ExportExcelServlet: application/vnd.ms-excel

    6/26/08 19:33:00:778 SGT 00000052 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.

    6/26/08 19:33:00:841 SGT 00000052 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet WebMNPPortInSummaryReport. Exception thrown : javax.servlet.ServletException: application/vnd.ms-excel

    at com.ibm.wps.pe.pc.std.invoker.impl.PortletServlet. convertException(PortletServlet.java:218)

    at com.ibm.wps.pe.pc.std.invoker.impl.PortletServlet. dispatch(PortletServlet.java:196)

    at com.ibm.wps.pe.pc.std.invoker.impl.PortletServlet. doPost(PortletServlet.java:76)

    at javax.servlet.http.HttpServlet.service(HttpServlet .java:763)

    ........

    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava(Compiled Code))

    Caused by: java.lang.IllegalArgumentException: application/vnd.ms-excel

    .........



    6/26/08 19:33:00:872 SGT 00000052 ServletWrappe E SRVE0014E: Uncaught service() exception root cause WebMNPPortInSummaryReport: java.lang.IllegalArgumentException: application/vnd.ms-excel

    at org.apache.pluto.core.impl.RenderResponseImpl.setC ontentType(RenderResponseImpl.java:152)

    at javax.servlet.ServletResponseWrapper.setContentTyp e(ServletResponseWrapper.java(Compiled Code))

    at webmnpportinsummaryreport.ExportExcelServlet.doGet (ExportExcelServlet.java:29)

    at javax.servlet.http.HttpServlet.service(HttpServlet .java:743)

    at javax.servlet.http.HttpServlet.service(HttpServlet .java(Compiled Code))

    at com.ibm.ws.webcontainer.servlet.ServletWrapper.ser vice(ServletWrapper.java(Compiled Code))

    ...........

  4. Re: How to export data to Excel form a portlet?

    yep this is as expected, you will have to open a pop up window and do a sendredirect to the servlet, or open a popup window right to the servlet, you cannot change the contenttype in a portlet, and by doing a rd.include you are trying to include that servlet into the portlet output and that trys to change the contenttype, first of you are trying to set it to one the portlet container does not support, second problem is that you cannot change the contenttype in a portlet because portal has already set it for you





    IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

    IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0



    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

  5. Re: How to export data to Excel form a portlet?

    "you will have to open a pop up window and do a sendredirect to the servlet, or open a popup window right to the servlet"



    i am not quite understand what should i do for that? is that mean when i call the pop up widow then i set the content type and do the processing to save data to excel file?



    can you give me a piece of code to help me to understand it.. very appreciate for your reply.. thanks!

  6. Re: How to export data to Excel form a portlet?

    your window.open code should point to the servlet not to jsp. so that your servlet can get the data from database, generate xls and push the xls to the popup window.

  7. Re: How to export data to Excel form a portlet?

    how to call a pop up from the servlet? can you show me some example.. thanks

+ Reply to Thread