更改来自 Java 库的提示错误消息
Change Prompt Error Message From Java Library
目前我正在使用 zkoss、java 和 maven。我的应用程序中的一项功能是上传文件。
当我通过上传一个非常大的文件对此功能进行一些测试时,我收到一条提示错误消息,上面写着
"the request was rejected because its size (8356577) exceeds the configured maximum (1024000)"
经过多次调试,我发现提示信息来自org.apache.commons.fileupload.FileUploadBase,这是我的maven依赖之一的文件。
现在,我想将错误消息更改为其他内容。有没有关于如何做的解决方案?我更喜欢不重新编译库的方式。非常感谢。
-- 已更新 --
这是我的web.xml。我做错什么了吗?再次感谢。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Sistem Informasi Jabatan Fungsional</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-ctx.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<session-config>
<session-timeout>15</session-timeout> <!-- in minutes -->
</session-config>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- For using session scoped bean -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<servlet-name>uploader</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
<init-param>
<param-name>extention0</param-name>
<param-value>/upload=uploader.UploadUtil</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<!-- Must. Specifies URI of the update engine (DHtmlUpdateServlet). It must be the same as <url-pattern>
for the update engine. -->
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup><!-- MUST -->
</servlet>
<servlet>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<!-- Spring Security Filter Start Here -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Security Filter End Here -->
<welcome-file-list>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>
您可以从 org.zkoss.zk.au.http.AuUploader
扩展并覆盖 handleError(Throwable)
方法:
public class MyUploader extends AuUploader {
@Override
protected String handleError(Throwable ex)
{
return "mymessage";
}
}
那么你必须在 web.xml:
中配置这个扩展
在
的配置中
<servlet>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
<!-- extentions here -->
</servlet>
添加:
<init-param>
<param-name>processor0</param-name>
<param-value>/upload=uploader.MyUploader</param-value>
</init-param>
可能 processor0
必须更改为 extention0
,具体取决于您的 ZK 版本。 processor0
已使用 ZK 7 进行测试。
可以找到有关此事的 ZK 文档 here。
目前我正在使用 zkoss、java 和 maven。我的应用程序中的一项功能是上传文件。
当我通过上传一个非常大的文件对此功能进行一些测试时,我收到一条提示错误消息,上面写着 "the request was rejected because its size (8356577) exceeds the configured maximum (1024000)"
经过多次调试,我发现提示信息来自org.apache.commons.fileupload.FileUploadBase,这是我的maven依赖之一的文件。
现在,我想将错误消息更改为其他内容。有没有关于如何做的解决方案?我更喜欢不重新编译库的方式。非常感谢。
-- 已更新 --
这是我的web.xml。我做错什么了吗?再次感谢。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Sistem Informasi Jabatan Fungsional</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-ctx.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<session-config>
<session-timeout>15</session-timeout> <!-- in minutes -->
</session-config>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- For using session scoped bean -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<servlet-name>uploader</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
<init-param>
<param-name>extention0</param-name>
<param-value>/upload=uploader.UploadUtil</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<!-- Must. Specifies URI of the update engine (DHtmlUpdateServlet). It must be the same as <url-pattern>
for the update engine. -->
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup><!-- MUST -->
</servlet>
<servlet>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<!-- Spring Security Filter Start Here -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Security Filter End Here -->
<welcome-file-list>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>
您可以从 org.zkoss.zk.au.http.AuUploader
扩展并覆盖 handleError(Throwable)
方法:
public class MyUploader extends AuUploader {
@Override
protected String handleError(Throwable ex)
{
return "mymessage";
}
}
那么你必须在 web.xml:
中配置这个扩展在
的配置中<servlet>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
<!-- extentions here -->
</servlet>
添加:
<init-param>
<param-name>processor0</param-name>
<param-value>/upload=uploader.MyUploader</param-value>
</init-param>
可能 processor0
必须更改为 extention0
,具体取决于您的 ZK 版本。 processor0
已使用 ZK 7 进行测试。
可以找到有关此事的 ZK 文档 here。