Java web的读取Excel简单Demo
目录结构:

Data.xls数据:

后台页面:
GetExcelData.java
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//System.out.println(this.getServletContext().getRealPath ("/"));
try{
Workbook wb = Workbook.getWorkbook(
new File(this.getServletContext().getRealPath ("/")+"data.xls"));
System.out.println("2222222");
List<Data> data = new ArrayList<Data>();
for(int i=1;i<wb.getSheet(0).getRows();i++){
Cell[] cell = wb.getSheet(0).getRow(i);
data.add(new Data(cell[0].getContents(),cell[1].getContents(),cell[2].getContents()));
System.out.println(cell[1].getContents());
}
wb.close();
request.setAttribute("data", data);
request.getRequestDispatcher("../index.jsp").forward(request, response);
}catch(Exception e){
e.printStackTrace();
}
}
Data.java
public class Data {
private String id;
private String name;
private String password;
public Data() {
super();
// TODO Auto-generated constructor stub
}
public Data(String id, String name, String password) {
super();
this.id = id;
this.name = name;
this.password = password;
}
public String getId() {
return id;
}
----------
前台页面:
Index.jsp:
<body>
<form action="servlet/getExcelData" method="post">
<input type="submit" id="tijiao" value="submit">
</form>
<%
List<Data> data = new ArrayList<Data>();
data=(List<Data>)request.getAttribute("data");
if(data!=null&&data.size()>0)
for(Data d:data){
out.println(d.getId()+"---"+d.getName()+"---"+d.getPassword());
}
%>
</body>
运行结果:

Java web的读取Excel简单Demo的更多相关文章
- JAVA使用POI读取EXCEL文件的简单model
一.JAVA使用POI读取EXCEL文件的简单model 1.所需要的jar commons-codec-1.10.jarcommons-logging-1.2.jarjunit-4.12.jarlo ...
- java 使用POI读取excel数据
原文:http://doc.okbase.net/0201zcr/archive/161440.html 一.定义 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Ja ...
- Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决
Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决 引言: 在Java中 ...
- java web 中 读取windows图标并显示
java web中读取windows对应文件名的 系统图标 ....显示 1.获取系统图标工具类 package utils; import java.awt.Graphics; import j ...
- 第四篇:java读取Excel简单模板
场景:对于经常需要导入Excel模板或数据来解析后加以应用的,使用频率非常之高,做了一个比较稳定的版本,体现在这些地方工具:org.apache.poi使用前必须了解这些:1.要解析,那肯定先判断是不 ...
- java导出和读取excel数据
使用的是poi的jar包 下载地址http://poi.apache.org/download.html 主要是把jar包导入,直接新建一个列子测试一下就明白了.使用起来还是比较方便的,代码里面的原理 ...
- java用poi读取Excel表格中的数据
Java读写Excel的包是Apache POI(项目地址:http://poi.apache.org/),因此需要先获取POI的jar包,本实验使用的是POI 3.9稳定版.Apache POI 代 ...
- Java实现POI读取Excel文件,兼容后缀名xls和xlsx
1.引入所需的jar包: maven管理项目的话直接添加以下坐标即可: <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -- ...
- easypoi 读取 Excel 简单应用
背景 在做接口测试的时候,经常会使用 Excel 来存储对应的接口信息和用例信息,为了方便程序的读取,引入easypoi 工具来读取 Excel 内容.easypoi 比起 poi 使用更加的方便,代 ...
随机推荐
- shell 编程中使用到得if语句内判断参数
http://blog.chinaunix.net/uid/21411227/cid-63616-list-1.html 1.判断文件类型 –b 当file存在并且是块文件时返回真 -c 当fil ...
- [原创]-IIS7.5优化,支持同时10万个请求
背景: IIS7.5是微软推出的最新平台IIS,性能也较以前有很大的提升,但是默认的设置配不适合很大的请求.但是我们可以根据实际的需要进行IIS调整,使其性能更佳,支持同时10万个请求. ...
- BootStrap2学习日记18---提示消息
代码: <div class="alert alert-block" id="alert"> <a href="#" cl ...
- 移动的rem自适应
(function (doc, win) { var docEl = doc.documentElement, //html resizeEvt = 'orientationchange' in wi ...
- 【阿里云产品公测】离线归档OAS,在也不用备份担心空间了
作者:阿里云用户 莫须有3i 1 起步 1.1 初识OAS 啥是OAS,请看官方说明: 引用 开放归档服务(Open Archive Service,简称OAS),致力于提供低成本.高可靠的数据归档服 ...
- Selenium html之于ul标志代码分析与使用
分析:https://github.com/页面Li <div class="header header-logged-out"> <div class=&quo ...
- Redis入门(优势,环境,字符串,哈希,列表)
Redis从它的许多竞争继承来的三个主要特点: Redis数据库完全在内存中,使用磁盘仅用于持久性. 相比许多键值数据存储,Redis拥有一套较为丰富的数据类型. Redis可以将数据复制到任意数量的 ...
- 剑指Offer36 数字在排序数组中出现的次数
/************************************************************************* > File Name: 36_Number ...
- Xcode6编译SDWebImage报错解决方法(SDWebImageDownloaderOperation.m错误)
报错:Use of undeclared identifier '_executing' / '_finished': 解决方法: 在SDWebImageDownloaderOperation类的实现 ...
- MSP下载方式
MSP430无论是仿真还是烧写程序,一般可以通过:JTAG.SBW.BSL接口进行. 1.JTAG是利用边界扫描技术,在430内部有逻辑接口给JTAG使用,内部有若干个寄存器连接到了430内部数据地址 ...