Skip to main content
added 10 characters in body
Source Link

aA really simple alternative is to call a servlet, that servlet returns an xls created from html table tags (this is suitable for really simple tables for complex ones you might want to use POI). fromFrom this resource http://www.coderanch.com/t/363613/Servlets/java/import-HTML-rows-ExcelCodeRanch resource.

in your jsp you have this:

  1. in your jsp you have this:

    <form method="post" action="DownloadAsExcel"> <input type="submit" name="submit" value="Download as Excel" /> </form>

  2. in your servlet DownloadAsExcel:

    public void doPost(HttpServletRequest req,HttpServletResponse res) { res.setContentType("application/vnd.ms-excel"); PrintWriter out=res.getWriter(); out.println(""); out.println("Hello James"); out.close(); }

<form method="post" action="DownloadAsExcel"> <input type="submit" name="submit" value="Download as Excel" /> </form>

in your backend :

public class DownloadAsExcel extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res) { res.setContentType("application/vnd.ms-excel"); PrintWriter out=res.getWriter(); out.println("<table>"); out.println("<tr bgcolor=lightblue><td>Hello </td><td>James</td></tr>"); out.close(); } } 

a really simple alternative is to call a servlet, that servlet returns an xls created from html table tags (this is suitable for really simple tables for complex ones you might want to use POI). from this resource http://www.coderanch.com/t/363613/Servlets/java/import-HTML-rows-Excel:

  1. in your jsp you have this:

    <form method="post" action="DownloadAsExcel"> <input type="submit" name="submit" value="Download as Excel" /> </form>

  2. in your servlet DownloadAsExcel:

    public void doPost(HttpServletRequest req,HttpServletResponse res) { res.setContentType("application/vnd.ms-excel"); PrintWriter out=res.getWriter(); out.println(""); out.println("Hello James"); out.close(); }

A really simple alternative is to call a servlet, that servlet returns an xls created from html table tags (this is suitable for really simple tables for complex ones you might want to use POI). From this CodeRanch resource.

in your jsp you have this:

<form method="post" action="DownloadAsExcel"> <input type="submit" name="submit" value="Download as Excel" /> </form>

in your backend :

public class DownloadAsExcel extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res) { res.setContentType("application/vnd.ms-excel"); PrintWriter out=res.getWriter(); out.println("<table>"); out.println("<tr bgcolor=lightblue><td>Hello </td><td>James</td></tr>"); out.close(); } } 
Source Link

a really simple alternative is to call a servlet, that servlet returns an xls created from html table tags (this is suitable for really simple tables for complex ones you might want to use POI). from this resource http://www.coderanch.com/t/363613/Servlets/java/import-HTML-rows-Excel:

  1. in your jsp you have this:

    <form method="post" action="DownloadAsExcel"> <input type="submit" name="submit" value="Download as Excel" /> </form>

  2. in your servlet DownloadAsExcel:

    public void doPost(HttpServletRequest req,HttpServletResponse res) { res.setContentType("application/vnd.ms-excel"); PrintWriter out=res.getWriter(); out.println(""); out.println("Hello James"); out.close(); }