无法访问 App Engine 开发服务器上 servlet 过滤器中的会话数据

发布于 2024-11-04 07:56:49 字数 923 浏览 1 评论 0原文

我试图编写一个会话过滤器来集中我的应用程序引擎网络应用程序中的授权检查。

我的过滤器看起来像这样:

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2024-11-11 07:56:49

您正在尝试将“请求”对象转换为响应。

更改如下

HttpServletResponse httpResp = (HttpServletResponse) response;

You are trying to cast "request" object as response.

change as follows

HttpServletResponse httpResp = (HttpServletResponse) response;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文