下面是代码
package com.actions;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.struts2.ServletActionContext;
import com.beans.TjbryyBean;
import com.opensymphony.xwork2.ActionContext;
import com.util.ConnUtil;
/**
* 团体导入
*
* @author Administrator
*
*/
public class SaveXlsFileAction {
private File[] newsfile;
private String gzdw;
private String[] newsfileFileName;
ResultSet rs = null;
PreparedStatement pst = null;
TjbryyBean tb = new TjbryyBean();
public TjbryyBean getTb() {
return this.tb;
}
public void setTb(TjbryyBean tb) {
this.tb = tb;
}
public String tjttDr() {
String path1 = "";
HttpServletRequest request = ServletActionContext.getRequest();
for (int i = 0; i < this.newsfile.length; i++) {
File zl = this.newsfile[i];
String realname = this.newsfileFileName[i];
if ((zl != null) && (zl.exists()) && (zl.length() > 0L)) {
SimpleDateFormat f = new SimpleDateFormat("yyyyMMddhhmmss");
String time = f.format(Calendar.getInstance().getTime());
String str = realname.substring(realname.lastIndexOf("."),
realname.length());
File destFile = new File(ServletActionContext
.getServletContext().getRealPath(
"\\upload\\" + this.gzdw + "\\" + time + str));
path1 = path1 + "\\upload\\" + this.gzdw + "\\" + time + str;
this.tb = new TjbryyBean();
Workbook book = null;
int totalRow = 0;
String errorRows = "";
Connection conn = new ConnUtil().getConn();
String sql = "select harm_name from zy_harm";
try {
this.pst = conn.prepareStatement(sql);
this.rs = this.pst.executeQuery();
List<String> list = new ArrayList();
while (this.rs.next()) {
list.add(this.rs.getString(1));
}
InputStream is = new FileInputStream(zl);
book = WorkbookFactory.create(is);
Sheet hssfSheet = book.getSheetAt(0);
totalRow = hssfSheet.getLastRowNum();
if(totalRow>200){
request.setAttribute("errors", "为了保证文件传输速度数据,数据量最大为200条!超过请分多次上传!");
return "success";
}
int num=0;
for (int ii = 1; ii <= hssfSheet.getLastRowNum(); ii++) {
num=ii;
Row row = hssfSheet.getRow(ii);
if (row != null) {
if (row.getCell(5) != null) {
if ("职业".equals(row.getCell(5).getStringCellValue())) {
System.out.println(" 姓名"+row.getCell(0));
String jhyy = "";
if ((row.getCell(3) != null)&& (row.getCell(3).getCellType() == 1)) {
jhyy = row.getCell(3).getStringCellValue();
if (!checkJhyy(jhyy, list)) {
errorRows = errorRows + (ii + 1)+ "、";
}
}
}
}else{
request.setAttribute("zt", "表格中第 "+ii+"行 ,第5列未获取到数据!请检查!");
}
}
}
if (!"".equals(errorRows)) {
request.setAttribute("errors", "表格中第 " + errorRows
+ " 行中的危害因素名称与数据库中不相符,无法保存表格。"
+ "\\n请重新填写标准的危害因素名称!\\各危害因素之间请用中文输入法下的顿号隔开!");
} else {
FileUtils.copyFile(zl, destFile);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return "success";
}
public boolean checkJhyy(String jhyy, List<String> list) {
boolean flag = true;
boolean temp = true;
String[] jhyys = jhyy.split("、");
for (int i = 0; i < jhyys.length; i++) {
for (int j = 0; j < list.size(); j++) {
if (jhyys[i].equals(list.get(j))) {
temp = true;
break;
}
temp = false;
}
if (!temp) {
break;
}
}
if (!temp) {
flag = false;
}
return flag;
}
public File[] getNewsfile() {
return this.newsfile;
}
public void setNewsfile(File[] newsfile) {
this.newsfile = newsfile;
}
public String[] getNewsfileFileName() {
return this.newsfileFileName;
}
public void setNewsfileFileName(String[] newsfileFileName) {
this.newsfileFileName = newsfileFileName;
}
public String getGzdw() {
return this.gzdw;
}
public void setGzdw(String gzdw) {
this.gzdw = gzdw;
}
}
兄弟 。 你把报错发出来啊。 找不到action是什么 404?
404
你这个问题解决了吗?我也遇到了这个问题,xls大于10K后,上传时连action也不会进去了,小于10K就正常。测试环境一切正常,正式环境就出现上面说的问题。