JSP 页面部分<form name="upload" action="upload.action" method="post" enctype="multipart/form-data">
  <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="bordercol_01">
  <tr>
    <td class="coltitle_01"></td>
  </tr>
  <tr>
    <td height="40" align="center"><table width="90%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="30%"> <input type="file" name="excelFile" /> </td>
    <td width="70%"><input class="submit_01" type="submit" value="上 传" /></td>
    <!--<td width="30%"><input type="text" name="name" label="username" ></td>  -->
  </tr>
</table>
</form>
struts.xml<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
    <constant name="struts.devMode" value="true" />
 
<package name="default" namespace="/" extends="struts-default">
        <action name="upload" class="com.wondersgroup.jxkh.dataimport.web.DataImpAction" method="uplodaFile">
            <result name="success" >wel.jsp</result>
            <result name="input" >wel.jsp</result>
        </action>
    </package>
</struts>Action:
package com.wondersgroup.jxkh.dataimport.web;import java.io.File;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.interceptor.ServletRequestAware;import com.opensymphony.xwork2.ActionSupport;
import com.wondersgroup.jxkh.dataimport.bo.FileInfo;
import com.wondersgroup.jxkh.dataimport.service.DataImpService;public class DataImpAction extends ActionSupport {

private File excelFile;
private HttpServletRequest req;
private DataImpService service;

public String uplodaFile(){
if(this.excelFile == null)
return INPUT;
FileInfo fileInfo = new FileInfo();
fileInfo.setFile(excelFile);
fileInfo.setFileName(excelFile.getName()); if(service.excelUpload(this.req,fileInfo)){
return SUCCESS;
}else{
return INPUT;
}
}


public File getFile() {
return excelFile;
} public void setFile(File file) {
this.excelFile = file;
} public HttpServletRequest getReq() {
return req;
} public void setReq(HttpServletRequest req) {
this.req = req;
} public DataImpService getService() {
return service;
} public void setService(DataImpService service) {
this.service = service;
}

}
文件提交之后进到action里面,然后获取到的excelFile总之为null。
找了大半天没有搞清楚怎么回事,大家帮忙看下,谢谢了

解决方案 »

  1.   

     public File getFile() {
            return excelFile;
        }    public void setFile(File file) {
            this.excelFile = file;
        }这里的setter和getter不是随便写的,是有规则的,如下: public File getExcelFile() {
            return excelFile;
        }    public void setExcelFile(File file) {
            this.excelFile = file;
        }同理,其他的getter和setter方法也要类似的修改。因为,在数据注入的时候,默认是要找相应的setter方法的。
      

  2.   

    set/get方法一般都用自动生成的,你貌似是自己敲的吧。
      

  3.   

    private File excelFile;
    没有gett/sett方法