ExtJs文件上传(文本、Excel文件解析)

二话不说上代码

练习:

view:




ff










Action: public class FileForm extends ActionSupport implements ServletRequestAware , ServletResponseAware{ private File file; private String fileFileName; private HttpServletRequest request; private HttpServletResponse response; public File getFile() { return file; } public void setFile(File file) { this.file = file; } public String getFileFileName() { return fileFileName; } public void setFileFileName(String fileFileName) { this.fileFileName = fileFileName; } //读文本文件的。 public String execute() throws Exception { FileInputStream fi = new FileInputStream(this.getFile()); BufferedReader br = new BufferedReader(new InputStreamReader(fi)); String line =""; while((line= br.readLine())!=null){ System.out.println(line); } br.close(); response.reset(); PrintWriter writer = response.getWriter(); writer.write("{success:true}"); return null; } @Override public void setServletRequest(HttpServletRequest request) { this.request=request; } @Override public void setServletResponse(HttpServletResponse response) { this.response= response; } /*读Excel文件,也可以将文件里的内容插入到数据库中相应的jar为jxl.jar public void readExcel(File file) throws Exception{ try { Workbook book = Workbook.getWorkbook(file); Sheet se = book.getSheet(1); int rownum = se.getRows(); for (int i = 1; i < rownum; i++) { System.out.println(se.getCell(0,i)+","+se.getCell(1,i)+","+se.getCell(2,i)); } book.close(); } catch (Exception e) { e.printStackTrace(); } } */ s2: 其它略。。

你可能感兴趣的:(ExtJs文件上传(文本、Excel文件解析))