HttpServletResponseWrapper Status Code = 0
I am using HttpServletResponseWrapper to capture the status c开发者_如何学运维ode in a servlet filter. It seems to work fine.
I get a status of 200 when everything is ok. However when the app server cant find the requested item, I get back a 0. but in the browser it shows up as a 404.
Can someone explain this?
EDIT: This is a JAX-RS web app so I am guessing that if the app server can't match the path it returns without setting a status, then when the webserver see a status of 0 it replaces it with 404. Does this sound right?
I am late but probably the answer is still useful:
In the HttpServletResponseWrapper these methods need to be implemented:
@Override
    public void setStatus(int status) {
        super.setStatus(status);    
        this.status = status;
    }
    @Override
    public void sendError(int status) throws IOException {
        this.status = status;
        super.sendError(status);
    }
    @Override
    public void sendError(int status, String msg) throws IOException {
        this.status = status;
        super.sendError(status, msg);
    }
    @Override
    public void sendRedirect(String location) throws IOException {
        this.status = 302;
        super.sendRedirect(location);
    }
On case of 404 the setStatus is not called but sendError, you need to catch the status there.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论