Results 1 to 6 of 6

Thread: Redirect before rendering page

  1. #1
    Join Date
    Oct 2005
    Posts
    10

    Default Redirect before rendering page

    Hi
    I need to be able to redirect in the controller to some page before a page is rendered, like redirecting in referenceData(example user not logged in, redirect to login page). Can anybody help me on this?

    Cheers.
    Prins

  2. #2
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    38

    Default

    this sounds more like a filter or something... but if you wanted to use Spring, you could extend Dispatcher servlet and do some checking in that.

  3. #3
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    Darren Davison.
    Public Key: 0xE855B3EA

  4. #4
    Join Date
    Oct 2005
    Posts
    10

    Default

    yeah, this is in the right direction, i would like to be able to do somthing like this
    referenceData or formBackingObject throws Exception {
    if(!loggedIn)
    redirect to some jsp page
    else
    show the page was reference data for.
    }

    You know what i mean?
    Im also not sure what method this should be in.

    cheers.

  5. #5
    Join Date
    Jul 2005
    Posts
    28

    Default

    How about throwing a ModelAndViewDefiningException??

    I just found out about this exception and it looks pretty interesting. Sounds like just the thing you need.

  6. #6
    Join Date
    Jul 2005
    Posts
    246

    Default

    I use a filter for this sort of thing.

    I have a login filter that is initialised with the following parameters:-

    Code:
        <filter>
            <filter-name>login</filter-name>
            <filter-class>uk.co.mpcontracting.modules.security.filter.LoginFilter</filter-class>
            <init-param>
                <param-name>login-url</param-name>
                <param-value>/security/login.html</param-value>
            </init-param>
            <init-param>
                <param-name>login-success-url</param-name>
                <param-value>/secure/welcome.html</param-value>
            </init-param>
            <init-param>
                <param-name>login-error-url</param-name>
                <param-value>/security/loginError.html</param-value>
            </init-param>
            <init-param>
                <param-name>multiple-login-url</param-name>
                <param-value>/security/multipleLogin.html</param-value>
            </init-param>
            <init-param>
                <param-name>password-expired-url</param-name>
                <param-value>/secure/user/passwordExpired.html</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>login</filter-name>
            <url-pattern>/secure/*.html</url-pattern>
        </filter-mapping>
        <filter-mapping>
            <filter-name>login</filter-name>
            <url-pattern>/secure/*.form</url-pattern>
        </filter-mapping>
    So everything with the path /secure/*.html and /secure/*.form passes through the filter. I don't filter individual JSPs since they all live inside the WEB-INF directory so cannot be accessed individually anyway.

    My filter doesn't just detect the user not being logged in, it also detects if the user's password has expired, and whether the user is logged in at another machine and forwards appropriately.

    Chained behind the login filter is a permissions filter that assesses a logged in user's permission to access the requested resource based on permissions, roles, and group memberships.

    This is cleaner than doing stuff in referenceData or formBackingObject IMO.

    The Seraph project follows a similar idea - http://opensource.atlassian.com/seraph/ - and if you look through their code you can get an idea for how it's done.

    Bob

Similar Threads

  1. Replies: 22
    Last Post: Feb 4th, 2010, 01:37 AM
  2. Pageable data list with Hibernate
    By robmorgan in forum Data
    Replies: 23
    Last Post: Jul 24th, 2006, 06:12 PM
  3. Redirect page for unauthorized access
    By gmansoor in forum Security
    Replies: 3
    Last Post: Jul 15th, 2005, 01:20 PM
  4. Replies: 0
    Last Post: Jun 10th, 2005, 08:22 AM
  5. Replies: 2
    Last Post: Nov 8th, 2004, 06:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •