java - 覆盖文件上传拦截器的 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.allowed=根据操作,此消息仅允许 CSV 内容
解决方案
公共类 CsvFileUploadInterceptor 扩展 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);
}
}
推荐阅读
- multithreading - 如何在 Jmeter 中处理不同 IBM MQ 队列上的异步消息的性能测试(和报告)?
- reactjs - testing-library/react - 为什么 toHaveFocus 返回错误的焦点元素?
- git - git 为项目做出贡献 - 分支当前已签出
- solr - TYPO3 solr news 多个详细页面
- jersey-2.0 - 多值映射
尽管我从 Request 对象中获取了 formParams,但它没有被填充 - kubernetes - 将流量路由回特定的 pod
- docker - 在正常运行时间约 36 小时后 Dns 查找 docker 容器中断
- python - keras-yolov3 模型中预期输入和目标的格式和形状
- c++ - 如何制作一个 c++ 程序并在该目录中使用命令行输入和 ls?
- bots - 通过 php 和 Telegram Bot Api 发送 Zip 文件