473,667 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display records from Database to excel format in Browser in JAVA-POI

2 New Member
I am Using STRUTS1.4 in NetBeans5.5 IDE Here we have a JSP Page

<%@page contentType="te xt/html"%>
<%@page pageEncoding="U TF-8"%>
<%@ taglib uri="http://jakarta.apache. org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache. org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache. org/struts/tags-logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<html:form action="tableac tion">
<html:text property="table name"/>
<html:submit/>
</html:form>


</body>
</html>

and a Action Class
/*
* TableAction.jav a
*
* Created on August 10, 2007, 5:24 PM
*/

package com.myapp.strut s;

import javax.servlet.h ttp.HttpServlet Request;
import javax.servlet.h ttp.HttpServlet Response;
import org.apache.poi. hssf.usermodel. HSSFCell;
import org.apache.poi. hssf.usermodel. HSSFRow;
import org.apache.poi. hssf.usermodel. HSSFSheet;
import org.apache.poi. hssf.usermodel. HSSFWorkbook;

import org.apache.stru ts.action.Actio n;
import org.apache.stru ts.action.Actio nForm;
import org.apache.stru ts.action.Actio nMapping;
import org.apache.stru ts.action.Actio nForward;
import java.sql.*;
import javax.sql.*;
import java.io.*;
/**
*
* @author JavaUser
* @version
*/

public class TableAction extends Action {


private final static String SUCCESS = "success";


public ActionForward execute(ActionM apping mapping, ActionForm form,
HttpServletRequ est request, HttpServletResp onse response)
throws Exception {


response.setCon tentType("appli cation/excel");
TableBean tb= (TableBean)form ;

HSSFWorkbook wb = new HSSFWorkbook();
FileOutputStrea m fileOut=new FileOutputStrea m("C:/Documents and Settings/JavaUser/WebExcel/workbook.xls");
HSSFSheet sheet = wb.createSheet( tb.getTablename ());

DataSource ds = this.getDataSou rce(request);
Connection conn = ds.getConnectio n();
PreparedStateme nt ps= conn.prepareSta tement("select * from "+tb.getTablena me());
ResultSet rs = ps.executeQuery ();
int i =0;

while(rs.next() ) {
HSSFRow row = sheet.createRow ((short) i);
HSSFCell cell1= row.createCell( (short)1);
cell1.setCellVa lue(rs.getStrin g(1));
HSSFCell cell2= row.createCell( (short)2);
cell2.setCellVa lue(rs.getStrin g(2));
HSSFCell cell3= row.createCell( (short)3);
cell3.setCellVa lue(rs.getStrin g(3));
i++;
}

wb.write(fileOu t);
fileOut.close() ;

PrintWriter out = response.getWri ter();
out.println(fil eOut);
return null;
//return mapping.findFor ward("excelfile ");

}
}


With STRUTS FORM BEAN
/*
* TableBean.java
*
* Created on August 10, 2007, 5:20 PM
*/

package com.myapp.strut s;

import javax.servlet.h ttp.HttpServlet Request;
import org.apache.stru ts.action.Actio nErrors;
import org.apache.stru ts.action.Actio nMapping;
import org.apache.stru ts.action.Actio nMessage;

/**
*
* @author JavaUser
* @version
*/

public class TableBean extends org.apache.stru ts.action.Actio nForm {

private String tablename;

public TableBean() {
super();
// TODO Auto-generated constructor stub
}

public String getTablename() {
return tablename;
}

public void setTablename(St ring tablename) {
this.tablename = tablename;
}


}

I have to get the result page directly in the Browser. Please Help me to Solve this Problem. I am using POI Library files to do this task.
Oct 11 '07 #1
2 3898
JosAH
11,448 Recognized Expert MVP
I've moved your question to the Java Forum section where it belongs.

kind regards,

Jos
Oct 11 '07 #2
r035198x
13,262 MVP
Use code tags when posting code.
So what's the problem exactly? Are you getting errors/exceptions?
Oct 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11307
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 Using this,I am first extracting data from given excel file into a temporary DataTable. After making some operations on that DataTable (like splitting one column into two), I am saving the data into actual
3
2907
by: DataBard007 | last post by:
My Access 97 database has a form that contains text boxes that display people's names, addresses, phone numbers, etc. The record source is a single table. I created a NextRecord and Previous Record command button that, when clicked, will display the next record and the previous record, respectively. But what if I want a quick glance at all my records? Is there a way to get the records to display automatically, one after another, with a...
1
2890
by: Eric Keung | last post by:
Hi all, my case is I want to get an image from access database and I just know it's "OLE object" field type at access I also don't know how to insert it into access here is my code and it just can display a invalid image try dim strConn as string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
2
6921
by: Mustufa Baig | last post by:
Hi everybody, I have an ASP.NET website where clients can view their monthly billings by selecting different options. One of the option is the way they want to see the report i.e. whether they want to see it in PDF or EXCEL etc etc..... What I am trying to acheive is depending on their choice of format, I want to send the stream of that particulae selected format to the browser. I have tried couple od solutions but I couldn't able to get...
1
3159
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream As System.IO.MemoryStream = 3 myReport.ExportToStream( ExportFormatType.PortableDocFormat) 4 Response.Clear() 5 Response.Buffer() = True
8
4604
by: hyper-sensitive | last post by:
Hi Can some body suggest me which approach I should follow to import millions of records from data base into an excel sheet? I am working with ver. 2000 of MS-Excel . The requirement is to dynamically load 65,000 rows to one excel-grid(worksheet) ,then create and load the other grids(worksheets) till the data has been loaded fully. How can I do this using the Filestream object ,in a very short span of time like some seconds? Here,...
14
23148
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So, we're looking for a way to display the page with a "please wait..." message while the process is running, and then, when the process is done, update the page with the actual results/page content. We have a page that opens another browser/page...
4
1597
LacrosseB0ss
by: LacrosseB0ss | last post by:
hello all; just wondering if this can be done. If so, I am looking for how to do it. I have a small Access macro that links 2 tables based on an address then assigns the address an ID based on the 2nd table's records. The address is taken from an imported Excel sheet, this funtionailty works like a charm. What I would like to do is say "Select * From Tbl1 Inner Join qry1 ON Tbl1 (Tbl1.Address = qry1.Address)". Now, this also works ok....
13
2981
by: Peter | last post by:
VS2008 ans ASP.NET 3.5, Office 2003 What is the best way to run Excel Template from ASP.NET web page were the Excel is only installed on the client without any ActiveX? If so can someone point me to an example? Do not have Sharepoint. This is for Intranet and security is not important. Thank You
12
4914
by: petter | last post by:
Hi! I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month. I have an Access database where I want to create a query to count all the internal units in my list (the “input”-table), between two dates. I want my list to be grouped by year and month. Here is the SQL-code, as called from VBA: strSQL_INTU1 = "PARAMETERS DateTime, DateTime;" _ ...
0
8457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8788
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8646
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.