Vita Rara: A Life Uncommon

Thanks a lot! So i have a

Thanks a lot!

So i have a new version of the interceptor-method:

    public String intercept (ActionInvocation invocation) throws Exception {
        //get the session
        Map attributes = invocation.getInvocationContext().getSession();

        // Is there a "user" object stored in the user's HttpSession?
        Object user = attributes.get(USER_HANDLE);
        if (user == null) {
            // The user has not logged in yet.

            // Is the user attempting to log in right now?
            Map parameters = invocation.getInvocationContext().getParameters()
            
            String loginAttempt = parameters.get( LOGIN_ATTEMPT);
            if (! StringUtils.isBlank (loginAttempt) ) { // The user is attempting to log in.

                // Process the user's login attempt.
                if (processLoginAttempt (request, session) ) {
                    // The login succeeded send them the login-success page.                    
                    return "login-success";
                } else {
                    // The login failed. Set an error if we can on the action.
                    Object action = invocation.getAction ();
                    if (action instanceof ValidationAware) {
                        ((ValidationAware) action).addActionError ("Username or password incorrect.");
                    }
                }
            }

            //put the address of the action called originally into the session
            String urlGoingTo = invocation.getProxy().getNamespace()+"/"+
            invocation.getProxy().getActionName()+".action";
        
            attributes.put( "GOING_TO", urlGoingTo);
            // Either the login attempt failed or the user hasn't tried to login yet, 
            // and we need to send the login form.
            
            
            return "login";
        } else {
            return invocation.invoke ();
        }
    }

It's a little nicer looking because it gets maps of the parameters and session-attributes instead of using the more clumpsy HttpSession/HttpServletRequest-classes.

The url is saved into the session (GOING_TO) and can be used in the login.jsp to redirect to where the user wanted to go originally.

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
  • Allowed HTML tags: <a> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <h1> <h2> <h3>
  • Lines and paragraphs break automatically.
More information about formatting options