Flask接口签名sign原理与实例代码浅析
225
2023-07-15
Java web的读取Excel简单实例代码
目录结构:
Data.xls数据:
后台页面:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Systehttp://m.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 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.passwhttp://ord = password; } public String getId() { return id; } 前台页面: Index.jsp:
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.passwhttp://ord = 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()+VCSQGL"---"+d.getPassword());
}
%>
运行结果:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~