Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to export data to Excel form a portlet?

69 views
Skip to first unread message

wangm...@hotmail.com

unread,
Jun 25, 2008, 9:21:17 PM6/25/08
to
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/developerworks/forums/thread.jspa?messageID=13987685&#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!!

Jim Barnes

unread,
Jun 26, 2008, 6:56:21 AM6/26/08
to
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

wangm...@hotmail.com

unread,
Jun 26, 2008, 7:20:40 AM6/26/08
to
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.setContentType(RenderResponseImpl.java:152)

at javax.servlet.ServletResponseWrapper.setContentType(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.java(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.setContentType(RenderResponseImpl.java:152)

at javax.servlet.ServletResponseWrapper.setContentType(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.service(ServletWrapper.java(Compiled Code))

..........

Jim Barnes

unread,
Jun 26, 2008, 7:26:56 AM6/26/08
to
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

wangm...@hotmail.com

unread,
Jun 26, 2008, 11:40:20 AM6/26/08
to
"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!

san_...@yahoo.com

unread,
Jun 26, 2008, 7:05:17 PM6/26/08
to
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.

wangm...@hotmail.com

unread,
Jun 26, 2008, 9:41:24 PM6/26/08
to
how to call a pop up from the servlet? can you show me some example.. thanks
0 new messages