开发者

gwt appengine - user service return page

开发者 https://www.devze.com 2023-01-29 07:27 出处:网络
I have an entire gwt home page, it has a sign in button (rpc). This is the service implementation (just like the example):

I have an entire gwt home page, it has a sign in button (rpc).

This is the service implementation (just like the example):

UserService userService = UserServiceFactory.getUserService();
        HttpServletRequ开发者_如何学运维est request = this.getThreadLocalRequest();
    String message = "";
    String thisURL = request.getRequestURI();

    Principal principal = request.getUserPrincipal();
    if(principal == null){
        message = "<p>Please <a href=\"" + userService.createLoginURL(thisURL) + "\">sign in</a>.</p>";
    }
    else{
        message = "Hola " + principal.getName() + ". Puedes <a href=\"" + 
                    userService.createLogoutURL(thisURL)+ "\">sign out</a>.</p>";
    }
    return message;

I let the doGet method empty.

Then, when I sign in/sign out it redirects me to a blank page (to myApp/myServlet), but I want to back to the page I was (my gwt home or wherever I was).


Point A: request.getRequestURI(); method. This method would always return the URL of the servlet where the current request is being processed.

Point B: In userService.createLoginURL(thisURL) , the thisURL is actually the URL where the user should be redirected to after successful login. In your case, thisURL point to your current the servlet path and not where you want the user to be redirected to (refer point A)

That is, if your page where you want to redirect user after successful login is www.yourapp.com/home, what you actually need to do is something like this:

UserService userService = UserServiceFactory.getUserService();
        HttpServletRequest request = this.getThreadLocalRequest();
    String message = "";
    String thisURL = "http://www.yourapp.com/home";

    Principal principal = request.getUserPrincipal();
    if(principal == null){
        message = "<p>Please <a href=\"" + userService.createLoginURL(thisURL) + "\">sign in</a>.</p>";
    }
    else{
        message = "Hola " + principal.getName() + ". Puedes <a href=\"" + 
                    userService.createLogoutURL(thisURL)+ "\">sign out</a>.</p>";
    }
    return message;

^Note the value being set for thisURL.

0

精彩评论

暂无评论...
验证码 换一张
取 消