目录结构
Data.xls 数据:
后台页面
Public void Doget (solicitação httpServletRequest, httpServletResponse Response) lança servleTexception, ioexception {//system.out.println(this.getServletContext( ).getRealPath ("/"); tente {WorkBoyBox WB = Workbook.getworkbook (novo arquivo (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 ++) {célula [] célula = wb.getSheet (0) .getRow (i); data.add (novos dados (célula [0] .getContents (), célula [1] .getContents (), célula [2] .getContents ())); System.out.println (célula [1] .getContents ()); } wb.close (); request.setAttribute ("dados", dados); request.getRequestDispatcher ("../ index.jsp"). Forward (solicitação, resposta); } catch (Exceção e) {e.printStackTrace (); }} Data.java
public class Data {private String ID; nome de string privado; senha de sequência privada; public data () {super (); // TODO Construtor GOERATIDO AUTO GRAVO STUB} Public Data (ID da String, Nome da String, String Senha) {super (); this.id = id; this.name = nome; this.password = senha; } public string getId () {return id; }前台页面
Index.jsp:
<Body> <formaction = "servlet/getExcelData" method = "post"> <input type = "submit" id = "tijiao" value = "submit"> </mand> <% list <data> data = new ArrayList <Data> (); dados = (list <data>) request.getAttribute ("dados"); if (dados! } %> </body>运行结果
以上这篇 Java web 的读取 Excel 简单实例代码就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。