WebSphere Portal Server - How to export data to Excel form a portlet?

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > January 2007 > How to export data to Excel form a portlet?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to export data to Excel form a portlet?

2007-01-24, 7:51 am

Hello

I need to develop a portlet from which I can export data to Excel. The data keept in a HashMap are presented in a table format, when portlet in VIEW mode. When pressing an "Export" button I would like to be presented with a popup asking if I want to Ope
n / Save the Excel file or Cancel the operation.

The Java code I am using in a JSP is :

<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>

<%

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition",
"attachment; filename=tabella11.xls");
// attachment - since we don't want to open
// it in the browser, but
// with MS-Excel, and set the
// default file name to use.
response.setHeader("CacheControl", "no-cache");
response.setHeader("pragma","no-cache");
response.setHeader("Expires","-1");

StringBuffer recordString = new StringBuffer();
recordString.append("<HTML><body><table>");
recordString.append("<tr><td>hello</td></tr>");
recordString.append("</table>");
String str = recordString.toString();

PrintWriter pw=response.getWriter();
pw.println(str);
%>

But unfortunatelly I get an exception:

2007.01.23 16:03:50.906 E com.ibm.wps.services.dispatcher.DispatcherServiceImpl handleRequest
java.lang.IllegalStateException: Writer already obtained

Can anyone help me please with some piece of code or an workaround for solving this issue?


Thanks in advance.


Otilia


2007-01-24, 1:17 pm

You should build a servlet for this. You can create a servlet in your portlet application.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com