GAE LoginAuthorization问题(不针对WEB-INF)

时间:2013-10-11 08:56:16

标签: google-app-engine jsp servlets

我在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,我就无法做到这一点。

当我对loginUrl使用RequestDispatcher时,

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)

Quesiton 2。 然后我尝试另一个sulotuion(重定向到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 ,错误“已经提交响应”。

我该怎么办?我无法找到解决方案

1 个答案:

答案 0 :(得分:-1)

记住,WEB-INF文件夹中的内容无法像你想要的那样提供。

尝试将test.jsp文件放在某处“正常”(root或root的子文件夹中)