Java web的读取Excel简单实例代码

目录结构:

Java web的读取Excel简单实例代码_第1张图片

Data.xls数据:

Java web的读取Excel简单实例代码_第2张图片

 

后台页面:

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 = new ArrayList(); 

      for(int i=1;i 
 

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:

 

<% List data = new ArrayList(); data=(List)request.getAttribute("data"); if(data!=null&&data.size()>0) for(Data d:data){ out.println(d.getId()+"---"+d.getName()+"---"+d.getPassword()); } %>

运行结果:

Java web的读取Excel简单实例代码_第3张图片

以上这篇Java web的读取Excel简单实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(Java web的读取Excel简单实例代码)