jsp - export to excel via link

Hi Everyone

This is my first post but ive done a lot of reading of the forums.

I'm working on a project where a user will enter data into a web form and a sql database will be searched and results displayed in tables in the browser. I have recently been asked to provide a function to export the tables to excel.

I have created a link from the results search.jsp to an export.jsp where i have :

<%@ page contentType="application/vnd.ms-excel"%>

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

response.setHeader("Content-disposition","attachment;filename=CIMMs.xls");%>

but this simply produces a blank xls file. even if i include

<jsp:include page="search.jsp"/>

the results of the search are not included it just puts blank tables in the xls file (which would be the output of search.jsp if no information was provided by the user)

Can anyone show me how to produce the xls file with the info being displayed in search.jsp?

Any help will be much appreciated?

[1178 byte] By [Ryion69a] at [2007-11-27 10:37:31]
# 1

this is an example servlet from ebook name "Core Java Servlet and JavaServer Page :

package coreservlets;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

/** Servlet that creates Excel spreadsheet comparing

* apples and oranges.

*/

public class ApplesAndOranges extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

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

PrintWriter out = response.getWriter();

out.println("\tQ1\tQ2\tQ3\tQ4\tTotal");

out.println("Apples\t78\t87\t92\t29\t=SUM(B2:E2)");

out.println("Oranges\t77\t86\t93\t30\t=SUM(B3:E3)");

}

}

hope this can help you.

secmaska at 2007-7-28 18:48:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

In your output jsp page, have a button like "Download to Excel', and then call the .do action in onclick event. In this .do action forward jsp should be the one which has the response header to download to excel.

skp71a at 2007-7-28 18:48:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks for your help.

Do you have any examples or links to examples of the .do method I have never encountered that before as im quite new to jsp and html?

Thanks

Ryion69a at 2007-7-28 18:48:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...