2012-06-26 57 views
1

在我struts.xml中我有:覆蓋Struts 2個的消息

<action name="file_save" method="fileSave" class="FileActionBean"> 
       <interceptor-ref name="fileUpload"> 
        <param name="maximumSize"> 
         5242880 
        </param> 
        <param name="allowedTypes"> 
         text/html 
        </param> 
       </interceptor-ref> 
       <interceptor-ref name="defaultStack"></interceptor-ref> 
       <result name="success" type="redirect">file</result> 
       <result name="error">error</result> 
</action> 

當我上傳的文件是大於5MB則不會引發錯誤。然後在我的struts.xml頂我:

<constant name="struts.multipart.maxSize" value="20971520" /> 

現在,當我上傳的文件的大小超過20MB則顯示錯誤信息更大。這是正常的行爲嗎?

如果是這樣,我怎麼配置struts來顯示攔截器的錯誤信息呢?

編輯1:

我使用Struts 2的版本2.1.8.1

+0

似乎全球conf覆蓋其他。 – Jaiwo99

+0

是的,這是正確的。通過遵循上一個鏈接,我也解決了這個問題。 – ThreaT

回答

0

你爲什麼不把你的文件大小驗證碼到你的動作類,然後在驗證方法檢查文件大小如果它違反,然後addActionError("your msg")並將其顯示在您的jsp中。

<constant name="struts.multipart.maxSize" value="-1"/> 

試試你的struts常量並設置攔截器文件的大小爲你想要的大小。

+0

我試過,但它仍然只顯示消息時,文件大小超過常數,而不是參數。 – ThreaT