简体   繁体   中英

App Engine returns error when used with User Services

I was trying to interate User Service to my App to restrict access. The app worked fine while in eclipse but once I deployed it to app engine it does not redirect to Google Login page as expected but comes with Error: Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds. This is a section of the servlet used:

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class MyLogin  extends HttpServlet {

    private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    UserService userService = UserServiceFactory.getUserService();

    String thisURL = "/home.html";

    resp.setContentType("text/html");
    if (req.getUserPrincipal() != null) {
        resp.getWriter().println("<p>Hello, " +
                                 req.getUserPrincipal().getName() +
                                 "!  You can <a href=\"" +
                                 userService.createLogoutURL(thisURL) +
                                 "\">sign out</a>.</p>");
    } else {
        resp.getWriter().println("<p>Please <a href=\"" +
                                 userService.createLoginURL(thisURL) +
                                 "\">sign in</a>.</p>");
    }
}
}

我可以通过将要保护的文件移出根目录来解决此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM