开发者

redirect the user once logged in to the requested page

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/开发者_JAVA技巧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


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");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜