A problem has been encountered in development:
You need to import Excel from the outside , get the data in it, and then save it to the database.
1. Upload using input on the JSP side first:
<form action= "Storeobdexcel" method= "POST"
Enctype= "multipart/form-data" >
<input type= "file" name= "Excelfile" onchange= "checkfile (This)" >
<input type= "Submit" value= "Import" >
</form>
2. Receive in action:
Private File Excelfile;
{Getter,setter omitted}
3, read the file (struts temporarily saved in temporary files, can be used directly)
Need to introduce Jxl.jar package,: "http://sourceforge.net/projects/jexcelapi/files/jexcelapi/2.6.12/"
Readexcel (This.excelfile);
Public arraylist<obdbean> readexcel (file file) {
Arraylist<obdbean> list=new arraylist<obdbean> ();
try {
Workbook wb=workbook.getworkbook (file);
Sheet sheet=wb.getsheet (0);
for (int i=1;i<sheet.getrows (); i++) {
for (int j=0;j<sheet.getcolumns (); j + +) {
Cell Cell=sheet.getcell (J, I);
System.out.println (Cell.getcontents ());
}
}
return list;
}
catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return list;
}
Successfully acquired and used
JSP struts2 imported into Excel and stored in the database