覆盖文件上传拦截器的 Struts 2 错误消息


<action name="upload" class="uploadManualAction">
<interceptor-ref name="fileUpload">
<param name="maximumSize">20971520</param>
<param name="allowedTypes">
application/pdf
</param>
</interceptor-ref>
<interceptor-ref name="logFilterStack"></interceptor-ref>
<result name="success">/jsp/confirmManualUpload.jsp</result>
<result name="error">/error/manualUploadError.jsp</result>
<result name="input">/jsp/manualUpload.jsp</result> 
</action>
this is the first action.


<action name="csvUploadAction" class="csvUploadAction" method="processReadCsv">
<interceptor-ref name="fileUpload">
<param name="maximumSize">20971520</param>
<param name="allowedTypes">
text/csv
</param>
</interceptor-ref>
<interceptor-ref name="logFilterStack"></interceptor-ref>
<result name="success">/jsp/csvUpload.jsp</result>
<result name="error">/error/manualUploadError.jsp</result>
<result name="input">/jsp/csvUpload.jsp</result> 
</action>
This is the second acton 

i want to overide 

struts.messages.error.content.type.not.allowed=只允许PDF内容 struts.messages.error.content.type.not.allow=仅允许此消息的 CSV 内容 到操作

public class CsvFileUploadInterceptor extensions FileUploadInterceptor {

private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(CsvFileUploadInterceptor.class);
@Override
protected String getTextMessage(Object action, String messageKey, String[] args) {
String actionName = action.getClass().getName();
if (actionName.endsWith(WebAppConst.CSV_UPLOAD_ACTION)) {
if (messageKey.equals(WebAppConst.STRUTS_MESSAGES_ERROR_FILE_TOO_LARGE)) {
messageKey = WebAppConst.CSV_UPLOAD_ERROR_FILE_TOO_LARGE;
} else if (messageKey.equals(WebAppConst.STRUTS_MESSAGES_ERROR_CONTENT_TYPE_NOT_ALLOWED)) {
messageKey = WebAppConst.CSV_UPLOAD_ERROR_CONTENT_TYPE_NOT_ALLOWED;
}
}
return super.getTextMessage(actionName, messageKey, args);
}

}

相关内容

  • 没有找到相关文章

最新更新