views:

186

answers:

1

Hi I have a form realm authentication with which i am securing a directory "secureUser"

well my question is: - How i can redirect the user once logged in to the requested page

the details: -

now i can log on a user using this (login.jsp)

    <form action="j_security_check" method="POST" id="login_from">
            <p>
    <input type="text" name="j_username" id="j_username" title="EmailID" />
                        </p>
                        <p>
    <input type="password" name="j_password" id="j_password" title="Password" />
                        </p>
                        <p>
    <input type="submit" name="Submit" id="Login" value="Login" />
                        </p>
            </form>

Now a user requests two or more pages in the same session browser (firefox/ie tabs) "secureUser/one.jsp" "secureUser/two.jsp" "secureUser/three.jsp"

Now the user gets a login form page thats login.jsp for all the three requested pages

The user authenticates into the page requested "secureUser/one.jsp"

Now if the user reloads the page "secureUser/two.jsp" or "secureUser/three.jsp" which is now showing login.jsp he gets the same login.jsp page

How i can redirect the user after logging in once to the requested page such that the page login.jsp after reloading goes to referred page

I can do this in the login.jsp page

        java.security.Principal obj = request.getUserPrincipal();

        if(obj!=null) 
        {
            response.sendRedirect("secureUser/one.jsp");
        }

but i cannot get the referred page such as two.jsp or three.jsp

Thanks Pradyut

A: 

you could add a

<input type="hidden" name="referrer" value="[[value]]" />

to your login form and populate [[value]] with the referrer. upon login or when the user is already logged in upon opending the login form, you can redirect your user to that page directly.

you will get the referrer with a call to this function:

request.getHeader("referer");
henchman
nope... its returning nullas the referer is the server itself.
Pradyut Bhattacharya
the referer normally contains the whole url, not only the server... perhaps a firewall or anything blocking this header? if not, find out the header names with HttpServletRequest.getHeaderNames() and choose the appropriate one
henchman
tried out withEnumeration enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { System.out.println("" + request.getHeader(enumeration.nextElement().toString()) ); }still could not get the referrer
Pradyut Bhattacharya