[Miles' Blog]

Welcome 2 My Planet

Available categories: [/] [development. ~]

关于wml中的response status code [Permalink]

Thu Nov 25 00:07:59 CST 2004
Category [working on downwap.]

没错,就是那个200/404/500。对于一般的浏览器,如果返回的status code不是200(HttpServletResponse.SC_OK),完全没有影响,会显示服务器定制的错误页面。比如:
http://2yup.com/blah 这就是我们通常所见的定制http error page了。

可是对于大多wml浏览器来说,可能是为了节省流量,只要分析到status code,就不会在去找页面,而是使用浏览器的默认错误页。这样适用于大多情况,可是,在我的应用中,我是利用500错误(Internal Server Error)来做统一的错误显示页面的。通过这种方法,只需要简单的抛出Exception,就能够方便的显示错误信息。这样就比较麻烦了--我的所有错误信息页面通通完蛋。

还好我们有filter可以用。对于wml应用,我都需要返回我的定制错误,所以,之前加入的WmlMimeFilter刚好满足条件。只需要在WmlMimeServletResponseWrapper里面,重载setStatus方法,就万无一失了:

    public void setStatus(int code) {
        super.setStatus(HttpServletResponse.SC_OK);
    }
结果正如所愿,丢失的错误信息全部回来了 /images/emoticons/grin.gif

附:一个完整的错误返回:
处理前 ==============
HTTP/1.x 500 Internal Server Error
Content-Type: text/vnd.wap.wml
Content-Length: 695
Date: Wed, 24 Nov 2004 16:14:13 GMT
Server: Apache-Coyote/1.1
Connection: close

处理后 ==============
HTTP/1.x 200 OK
Content-Type: text/vnd.wap.wml
Content-Length: 695
Date: Wed, 24 Nov 2004 16:19:02 GMT
Server: Apache-Coyote/1.1

Posted by: miles
Comments [0] |

?
四月 2024
Sun? Mon? Tue? Wed? Thu? Fri? Sat?
 123456
78910111213
14151617181920
21222324252627
282930    
       
<  Mar???Today??? May  >
<< <   1   > >>

Available categories: [/] [development. ~]

Powered By blojsom?? RSS Feed? RSS2 Feed? RDF Feed

html hits:?51253