Hi all,
I would like to know who is the current user logged in google account, when
i send a request to particular servlet. I got some part of the code from
Google app engine site.
I have uploaded required jar in to my application. I assumed, when i call
this servelet, this will populate the current user Email id.
While executing in
*User user = userService.getCurrentUser();
*
this part of the line it is throwing Null Pointer exception.
*Bellow is the Code i used*
package guestbook;
import java.io.IOException;
import javax.servlet.http.*;
*import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;*
public class GuestbookServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
*UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + user.getEmail());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}*
}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.