无法访问 App Engine 开发服务器上 servlet 过滤器中的会话数据
我试图编写一个会话过滤器来集中我的应用程序引擎网络应用程序中的授权检查。
我的过滤器看起来像这样:
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpResp = (HttpServletResponse) request;
HttpSession session = httpReq.getSession();
httpReq.setCharacterEncoding("UTF-8");
httpResp.setCharacterEncoding("UTF-8");
httpResp.setContentType("application/json");
Boolean isAuthorized = (Boolean) session.getAttribute("isAuthorized");
if (!isAuthorized || isAuthorized == null) {
httpResp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
} else {
chain.doFilter(request, response);
}
}
但是当我启动应用程序引擎开发服务器时,我遇到了这个异常:“org.mortbay.jetty.request 无法转换为 javax.servlet.http.httpservletresponse”。我做错了什么?
I was trying to write a session filter to centralize authorization check in my app engine web app.
My filter looks like this :
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpResp = (HttpServletResponse) request;
HttpSession session = httpReq.getSession();
httpReq.setCharacterEncoding("UTF-8");
httpResp.setCharacterEncoding("UTF-8");
httpResp.setContentType("application/json");
Boolean isAuthorized = (Boolean) session.getAttribute("isAuthorized");
if (!isAuthorized || isAuthorized == null) {
httpResp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
} else {
chain.doFilter(request, response);
}
}
But when I'm launching app engine dev server I'm greeted with this exception : "org.mortbay.jetty.request cannot be cast to javax.servlet.http.httpservletresponse". What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试将“请求”对象转换为响应。
更改如下
You are trying to cast "request" object as response.
change as follows