丿傲娇 2016-05-13 06:32 采纳率: 0%
浏览 1054

Strust2上传Xls文件 数据超过200条就找不到action

Strust2上传XLS文件的时候 文件中的数据超过200条就找不到action
我在本地限制了一下 但是到了服务器还是不找不到action

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 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;
    }
    }

  • 写回答

1条回答

  • threenewbee 2016-05-13 07:26
    关注

    把tomcat的超时设置和最大上传大小修改下。

    评论

报告相同问题?

悬赏问题

  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿