JSP struts2 imported into Excel and stored in the database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.