我正在尝试编写一个仅供我自己使用的谷歌应用引擎应用程序. (我知道这听起来很奇怪……暂时)我正在尝试编写一个Login servlet,它将使用google的UserService对用户进行身份验证,并且只有在我登录时才会让用户进入应用程序并显示一条提示注销的简短消息其他所有人.
这是我写的代码:
public class MainPageServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
resp.setContentType("text/html");
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
if(user.getEmail().equals("aaadith@gmail.com")) {
resp.getWriter().println("done");
}
else {
resp.getWriter().println("Hello, " + user.getNickname()+"
");
resp.getWriter().println("Thanks for your interest. But this application is still not available to everybody.");
resp.getWriter().println("Log out");
}
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
}
与“驱走”所有其他用户相关的代码工作正常.但是当我登录时遇到问题:登录后,它会按预期显示“已完成”消息.但是,在此之后,如果我从那里打开一些其他谷歌服务并注销并再次调用此servlet,它仍会显示消息“已完成”.我曾经期望应用程序会提示我再次登录……这种情况没有发生..我认为它发生了,因为结果是缓存而禁用缓存(方法中的第一行)……但问题仍然存在那……怎么了?我如何获得预期的行为?