package com;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
public class PermitAction extends DispatchAction
{
public ActionForward getPermitList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
String fuserId = request.getParameter("fuserId");
try
{
response.getWriter().print("<script>history.back();alert('hjhjhjhjhjh');</script>");
------------直接返回到当前页面----------
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}
}
数据导出:
// 导出Excel
// 先将数据导到服务器上的路径,然后下载
String path = request.getSession().getServletContext().getRealPath("excel") + File.separator + "locationresult.xls";
// 先将数据导到服务器上的路径:exportExcel 函数如下
this.exportExcel(sql.toString(), path);
File file = new File(path);
// application/vnd.ms-excel : 这个可去tomcat 配置文件(web.xml)中找 还有其他类型
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=locationresult.xls");
response.setContentType("application/x-msdownload");
InputStream is = new FileInputStream(file);
OutputStream os = response.getOutputStream();
int i = 0;
byte[] buffer = new byte[10240];
while ((i = is.read(buffer, 0, buffer.length)) > -1)
{
os.write(buffer, 0, i);
os.flush();
}
if (is != null)
{
is.close();
}
if (os != null)
{
os.close();
}
==================
public void exportExcel(String sql, String path)
{
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try
{
WritableWorkbook book = Workbook.createWorkbook(new File(path));
// 生成名为"第一页"的工作表,参数0表示这是第一页
WritableSheet sheet = book.createSheet("第u19968 页, 0);
// 在Label对象的构造子中指名单元格位置是第一列第一行(0,0) //以及单元格内容为test
conn = oracleToolIn.getConnection();//获取数据方法自己修改
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int colCnt = rsmd.getColumnCount();
for (int k = 1; k < colCnt + 1; k++)
{
String title = rsmd.getColumnName(k);
Label labelTitle = new Label(k - 1, 0, title);
sheet.addCell(labelTitle);
}
int i = 1;
while (rs.next())
{
for (int j = 1; j < colCnt + 1; j++)
{
String colName = rsmd.getColumnName(j);
String colValue = rs.getString(colName);
Label label = new Label(j - 1, i, colValue);
sheet.addCell(label);
}
i++;
}
book.write();
book.close();
}
catch (Exception e)
{
}
finally
{
try
{
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(conn!=null)
{
conn.close();
}
}catch (Exception e)
{
Log4jInit.logger().error(e.toString());
}
}
}
=================================
// 导出HTML
// 先将数据导到服务器上的路径,然后下载
String path = request.getSession().getServletContext().getRealPath("excel") + File.separator + "motesss.html";
this.exportHtml(sql.toString(), path);
response.setContentType("text/html");
response.setHeader("Content-Disposition", "attachment; filename=mouserlist.html");
response.setContentType("application/x-download");
InputStream is = new FileInputStream(path);
OutputStream os = response.getOutputStream();
int i = 0;
byte[] buffer = new byte[10240];
while ((i = is.read(buffer, 0, buffer.length)) > -1)
{
os.write(buffer, 0, i);
os.flush();
}
if (is != null)
{
is.close();
}
if (os != null)
{
os.close();
}
==================
public void exportHtml(String sql, String path)
{
PrintWriter pw = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = oracleToolIn.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
StringBuffer html = new StringBuffer("<table border=1>");
StringBuffer title = new StringBuffer("<tr>");
int colCnt = rsmd.getColumnCount();
for (int k = 1; k < colCnt + 1; k++)
{
title.append("<td>").append(rsmd.getColumnName(k)).append("</td>");
}
title.append("</tr>");
html.append(title.toString());
while (rs.next())
{
html.append("<tr>");
for (int j = 1; j < colCnt + 1; j++)
{
String colName = rsmd.getColumnName(j);
String colValue = rs.getString(colName);
html.append("<td>").append(colValue).append("</td>");
}
html.append("</tr>");
}
html.append("</table>");
File f = new File(path);
pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f),"gb2312"));
pw.write(html.toString());
pw.flush();
pw.close();
}
catch (Exception e)
{
Log4jInit.logger().error(e.toString());
}
finally
{
try
{
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(conn!=null)
{
conn.close();
}
}catch (Exception e)
{
Log4jInit.logger().error(e.toString());
}
}
}
分享到:
相关推荐
将simulink示波器数据导出到excel表格教程将simulink示波器数据导出到excel表格教程将simulink示波器数据导出到excel表格教程将simulink示波器数据导出到excel表格教程将simulink示波器数据导出到excel表格教程将...
ElasticSearch数据导出 elasticsearch单文档数据导出 支持自定义查询 导出数据Json文件
xlsx百万级模板数据导出,可以使用8M内存模板导出excel. easypoi和hutool对07版本的excel都没有提供模板导出,因此个人封装了下(原创)。 目前支持的模板表达式有 #if:表达式不成立则不输出#if #end中的行 #each ...
税务局数据导出工具。可以导出国内外,国内大部分财务管理软件的数据。
C#大量数据导出到Excel,超过65536行时自动分页导出
在PHP编程中,有时需要把数据表中的数据导出成表格的形式,这就需要……
SilvacoTonyplot中如何导出数据导出图片保存文件[汇编].pdf
可以把oracle中大量数据导出为txt格式,便于在线下载、存储等后续处理。已经测试过,可以执行。
elastic数据导出工具,可以直接将es中的数据导入存储到Mysql,也可以指定存储到本地文件夹中,可以选择以json格式或者sql语句的形式
本软件是专门针对单一窗口数据导出、软件可以支持单票、多票 ,批量导出到mssql、mysql 等主流数据库,还可以支持 一键上传随附单据,支持订制开发
轻松让java 将数据导出到Excel中,java让开发更简单。
数据导出到Excel.html ,数据导出到Excel.html
怎么定时自动将SQL数据导出为Excel文件
组态王历史数据导出EXCEL表格的方法.docx
这是一个关于C#把数据导出为Excel格式的一个实例,很实用的,还请大家多多指教呀,呵呵,有什么缺陷还请大家及时指正呀,呵呵!!!
五、数据过滤时,通过startRow和stopRow来过滤数据导出范围。 六、文件存储的绝对路径为:文件存储路径(配置)+文件名(程序自动生成)+文件扩展名(配置)。 其中,文件名的格式为:数据类型名称(可配)+下划线...
C#下成功登录后datagridview数据导出excel
VS中将GridView 中的数据导出至excel
数据库数据 导出为SQl语句 工具,支持 各种数据库 数据导出
此软件可以顺利的将数据库中的所有数据导出成为sql语句,用于数据导入导出是个不错的工具