为什么我得到的文件没有发现异常



我正面临struts2框架的问题。我想从html的形式在Action类中获得excel文件的数据。我得到异常,如-

jxl.read.biff.BiffException: The input file was not found

My Action class is -

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class UpdateZflexRecordsAction extends ActionSupport {
/**
 * 
 */
private static final long serialVersionUID = 1L;
private boolean result = false;
private String status = null;
private String msg = null;
public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
public String getMsg() {
    return msg;
}
public void setMsg(String msg) {
    this.msg = msg;
}
public String execute() {
    result = new sadagi.ericsson.softhuman.model.UpdateZflexRecordsModel()
            .UpdateZflexRecords();
    if (result) {
        this.setStatus("Success");
        this.setMsg("Congratulation ! Your request has been accepted.");
    } else {
        this.setStatus("Failled");
        this.setMsg("Sorry ! Your request has not been accepted.");
    }
    return Action.SUCCESS;
}

}

My Model class is-

import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletInputStream;
import jxl.*;
import jxl.read.biff.BiffException;
import org.apache.struts2.ServletActionContext;
public class UpdateZflexRecordsModel {
private Boolean result = false;
private ServletInputStream inputStream = null; 
public Boolean UpdateZflexRecords() {
    HttpServletRequest request = ServletActionContext.getRequest();
    System.out.println(request);//////////////////////////////
    try {
    inputStream = request.getInputStream();
    System.out.println(inputStream);//////////////////////////
    byte[] junk = new byte[1024];
    int bytesRead = 0;
    // strip off the HTTP information from input stream
    // the first four lines are request junk
    bytesRead = inputStream.readLine(junk, 0, junk.length);
    bytesRead = inputStream.readLine(junk, 0, junk.length);
    bytesRead = inputStream.readLine(junk, 0, junk.length);
    bytesRead = inputStream.readLine(junk, 0, junk.length);
    // create the workbook object from the ServletInputStream
    Workbook workbook = Workbook.getWorkbook(inputStream);
    Sheet sheet = workbook.getSheet(0);
    Cell cell = null;
    System.out.println(sheet.getName());
      workbook.close();
} catch (Exception e) {  System.out.println("exce-1");
    // TODO Auto-generated catch block
    e.printStackTrace();
} 
    return result;
}
}

我的struts.xml是-

 <?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
<struts>  
<constant name="struts.devMode" value="true" /> 
<constant name="struts.multipart.maxSize" value="10000000" />
<package name="default" extends="struts-default, json-default" namespace="/">
<action name="downloadZflexFormat" class="sadagi.my.pro.action.RootMapper" method="downloadZflexFormatAction">  
<interceptor-ref name="accessRequired"/>
<interceptor-ref name="scope" />
<result name="login" type="redirect">/</result>  

我的控制台显示异常,如-

org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper@51c2e8a4
org.apache.catalina.connector.CoyoteInputStream@533790eb
exce-1
jxl.read.biff.BiffException: The input file was not found
at jxl.read.biff.File.<init>(File.java:124)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at jxl.Workbook.getWorkbook(Workbook.java:253)
at  sadagi.pro.softhuman.model.UpdateZflexRecordsModel.UpdateZflexRecords(UpdateZflexRecordsModel.java:30)
at sadagi.pro.softhuman.action.UpdateZflexRecordsAction.execute(UpdateZflexRecordsAction.java:33)

请帮帮我由于

您将获得jxl.read.biff.BiffException: The input file was not found

getWorkbook() allowed only File(Excel,etc),InputStream但是你试着给输入类型ServletInputStream type it worng type.所以,通过Exception of FileNotFound

 private ServletInputStream inputStream = null;   // ServletInputStream Types
 Workbook workbook = Workbook.getWorkbook(inputStream);  

检查你的图书馆jxl.Workbook.getWorkbook()

public static Workbook getWorkbook(File file) throws IOException, BiffException {....  }
public static Workbook getWorkbook(File file, WorkbookSettings ws) throws IOException, BiffException {  .....   }
public static Workbook getWorkbook(InputStream in) throws IOException, BiffException { ....    }
public static Workbook getWorkbook(InputStream in, WorkbookSettings ws) throws IOException, BiffException {   .......  }

最新更新