-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Does anyone know how to catch the server 503 error thrown by the browser if the server has gone down?
Or another way to put this is catch a stale page, the server has cycled and is back up but our page is now stale.
In my case, if we are sitting on a page and the server is restarted, the next time the user presses anything it will pop the "503: Service Temporarily Unavailable" dialog, then when they hit ok the page will reload and all is well. I want to do that reload under the covers so the dialog never gets popped.
I haven't found anything on the web and was wondering if anyone knows a ZK way or any other way to do this. Thanks! Andy
You can specify reload-uri with respect to specific response code under error-reload element of client-config element in zk.xml, please refer to the sample below (also include error handling and session timeout)
zk.xml
<zk>
<!-- for response error, e.g., 500, 503 -->
<client-config>
<error-reload>
<device-type>ajax</device-type>
<error-code>500</error-code>
<reload-uri></reload-uri>
</error-reload>
<error-reload>
<device-type>ajax</device-type>
<error-code>503</error-code>
<reload-uri></reload-uri>
</error-reload>
</client-config>
<!-- for Exception throwed in Event Listener -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/refresh.zul</location>
</error-page>
<!-- for session timeout -->
<session-config>
<device-type>ajax</device-type>
<timeout-uri></timeout-uri>
</session-config>
</zk>
test.zul
<zk>
Test steps:
<div />
1. click 'response 503' button
<div />
2. click 'throw exception' button
<div />
3. Restart server then click 'test session timeout' button
<div />
<button label="response 503" onClick="alert(123);">
<attribute name="onClick"><![CDATA[
((javax.servlet.http.HttpServletResponse)Executions.getCurrent().getNativeResponse()).sendError(javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE);
]]></attribute>
</button>
<button label="throw exception">
<attribute name="onCreate"><![CDATA[
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
self.addEventListener(Events.ON_CLICK, new EventListener () {
public void onEvent (Event event) {
throw new Exception("");
}
});
]]></attribute>
</button>
<button label="test session timeout" onClick="alert(123);" />
<div />
loaded time: <label onCreate='self.setValue(System.currentTimeMillis() + "")' />
</zk>
refresh.zul (for error handling)
<zk>
<zscript><![CDATA[
Executions.getCurrent().sendRedirect("");
]]></zscript>
</zk>
References:
Asked: 2013-04-17 16:01:55 +0800
Seen: 18 times
Last updated: Jun 28 '13