开发者

JSF and Filter redirection generate blank page

开发者 https://www.devze.com 2023-02-18 12:34 出处:网络
This is driving me insane, is there any good way for redirecting JSF page from Filter? Here is my code in doFilter()

This is driving me insane, is there any good way for redirecting JSF page from Filter? Here is my code in doFilter()

       try {

            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (Htt开发者_开发问答pServletResponse) response;
            LoginAgent loginAgent = (LoginAgent) req.getSession().getAttribute("login");

            if (loginAgent == null || !loginAgent.isLoggedIn()) {
                res.sendRedirect("requireslogin.xhtml");
            }
            else {
                chain.doFilter(request, response);
            }

All I got is a blank page. I have tried other way but none works and I haven't met a good example on redirecting to another JSF page without involving too much work.

Is there any workaround for this? Basically the filter is used for disabling anonymous user from reaching pages.


Just for your information, in case if you are running into the same problem with me, and want an alternative way out, you can use phaseListener for checking user login status.

I am still stuck with the filter, but I figured I better opt this way (the PhaseListener), it is much easier to understand at least to me and more elegant (at least in my eyes, lol).

you can follow the guide from this guy's blog. Awesome one.

http://gurolerdogan.blogspot.com/2010/04/controlling-login-by-phaselistener-in.html

While some of you might encounter problem as every page shall be rerouted to the login page when user is not logged in, this is easily fixed by redefining your navigation rule in faces-config.

Thanks to whoever that bears with my noobity in handling JSF! Especially you, BalusC :)

0

精彩评论

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

关注公众号