<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<div>
<form action="admin/getUploadExce.action" method="post" enctype="multipart/form-data" >
<input type="file" name="uploadFile" id="uploadFile" />
<input type="submit" value="导入" class="but3" />
<br />
</div>
</center>
</div>
<!-- 操作功能区域结束 -->
</body>
</html>
struts.xml--------------------------
<action name="getUploadExce" class="examPaperAction" method="getUploadExcel">
</action>
action--------------------------
private File uploadFile;
private String uploadFileFileName;
/**
* @return the uploadFileFileName
*/
public String getUploadFileFileName() {
return uploadFileFileName;
}
/**
* @param uploadFileFileName the uploadFileFileName to set
*/
public void setUploadFileFileName(String uploadFileFileName) {
this.uploadFileFileName = uploadFileFileName;
}
/**
* @return the uploadFile
*/
public File getUploadFile() {
return uploadFile;
}
/**
* @param uploadFile the uploadFile to set
*/
public void setUploadFile(File uploadFile) {
this.uploadFile = uploadFile;
}
public String getUploadExcel() {
try {
InputStream in = new FileInputStream(uploadFile);//不用request.getInputStream();
XSSFWorkbook xwb;
xwb = new XSSFWorkbook(in);
// 读取第一章表格内容
XSSFSheet sheet = xwb.getSheetAt(0);
// 定义 row、cell
XSSFRow row;
int rows = sheet.getPhysicalNumberOfRows();
System.out.println("有效行数=" + rows);
/////////////////////
///其他代码//
//////////////////////
} catch (Exception e) {
e.printStackTrace();
}
return null;
}