2014-02-10 59 views
0

我們正在將我們的應用程序從struts 1遷移到struts 2模塊,並且我們正在使用struts2-strut1插件。文件上傳在Struts2-Struts1插件中無效其設置NULL

每件事似乎都正常工作,期望文件我們正在獲取文件屬性值爲NULL。

我們已經檢查過了看到我們的標籤下面的樣子

JSP代碼片斷

<s:form name="uploadForm" namespace="/struts2" action="upload" enctype="multipart/form-data" method="post"> 
    <s:file name="doc" cssClass="genTextValues"/> 
    <s:submit/> 
</s:form> 

的Java操作形式

public class UploadForm extends ActionForm {    
     private FormFile doc; 
     public FormFile getDoc() { 
      return doc; 
     } 
     // its not setting gives null in action form 
     public void setDoc(FormFile doc) { 
      this.doc = doc; 
     } 
    } 

的struts.xml映射

<interceptor name="uploadForm" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"> 
     <param name="scope">request</param> 
     <param name="className">com.form.UploadForm</param> 
     <param name="name">uploadForm</param> 
    </interceptor> 
    <interceptor-stack name="iUploadForm"> 
     <interceptor-ref name="staticParams" /> 
     <interceptor-ref name="uploadForm" /> 
     <interceptor-ref name="modelDriven" /> 
     <interceptor-ref name="basicStack" />  
    </interceptor-stack> 
    <action name="uploadDoc" class="org.apache.struts2.s1.Struts1Action"> 
     <param name="className">com.test.action.UploadAction</param> 
    <interceptor-ref name="iUploadForm"/> 
     <result name="Success" type="tiles">Success</result> 
    </action> 

我們已經添加所需的jar見下圖:

commons-fileupload.jar 
struts.jar 
struts2-struts1-plugin.jar 
struts2-core.jar (2.16) 
commons-io2.2.jar 

其他所需的罐子

回答

0

沒有fileUpload攔截在interceptor-stack

<interceptor-stack name="iUploadForm"> 
     <interceptor-ref name="staticParams" /> 
     <interceptor-ref name="fileUpload"/> 
     <interceptor-ref name="uploadForm" /> 
     <interceptor-ref name="modelDriven" /> 
     <interceptor-ref name="basicStack" />  
</interceptor-stack> 
+0

謝謝!!!我添加了攔截器,並將FormFile更改爲java.io.file,它工作得非常好。 – coolcoder