PDS*_*tat 3 servlets filter java-ee
我有一个实现javax.servlet.Filter对会话中设置的令牌对象进行一些身份验证的类,如果令牌变为无效我希望返回403禁止响应.所以我有类似的东西
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throw ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
...
...
// Something has gone wrong with auth set the response code and
// continue with the chain
response.setStatus(403);
chain.doFilter(request, response);
}
Run Code Online (Sandbox Code Playgroud)
我想要发生的是<error-page>web.xml中定义的触发403响应代码
<error-page>
<error-code>403</error-code>
<location>/forbidden.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
我可以看到浏览器开发工具的网络选项卡正确显示403类型响应.但浏览器没有像我期望的那样重定向到错误页面,我在这里做错了什么?
PDS*_*tat 10
我的错误是做response.setStatus(403)了需要发生的事情
response.sendError(403);
return;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5952 次 |
| 最近记录: |