我在 GAE 中有 OpenID 登录:
private static final Map<String, String> openIdProviders;
static {
openIdProviders = new HashMap<String, String>();
openIdProviders.put("Google", "https://www.google.com/accounts/o8/id");
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
Principal princ = req.getUserPrincipal();
Set<String> attributes = new HashSet<String>();
String provider =req.getParameter("openIdProvider");
for (String providerName : openIdProviders.keySet()) {
String providerUrl = openIdProviders.get(providerName);
if(providerName.equals(provider)){
String loginUrl = userService.createLoginURL("/test/manager.jsp", null, providerUrl, attributes);
resp.sendRedirect(loginUrl);
return;
}
}
}
一切都很好!
但我需要重定向到WEB-INF/test/manager.jsp
我知道没有 RequestDispatcher 就无法做到这一点。
当我将 RequestDispatcher 用于 loginUrl 时的1 个问题:
RequestDispatcher dispatch = req.getRequestDispatcher(loginUrl);
dispatch.forward(req, resp);
我有错误
java.lang.NullPointerException at com.google.appengine.api.users.dev.LoginCookieUtils.encodeEmailAsUserId(LoginCookieUtils.java:91)
问题2。 然后我尝试另一个 solotuion (重定向到 servlet。在这个 UserProfilePanel servlet 中,我将使用 RequestDispatcher 。
String loginUrl = userService.createLoginURL("/UserProfilePanel", null, providerUrl, attributes);
resp.sendRedirect(loginUrl);
但是,我有那个错误:
访问 /UserProfilePanel 时出现问题。原因:
Response has already been committed
Caused by:
java.lang.IllegalStateException: Response has already been committed
at com.google.appengine.repackaged.com.google.common.base.Preconditions.checkState(Preconditions.java:153)
我在 localhost 进行测试:当我输入邮件时,我被定向到localhost:8888/_ah/login?continue=/FUserProfilePanel,错误“响应已提交”。
我能做些什么?我找不到解决方案