Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 661853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:18:50+00:00 2026-05-13T23:18:50+00:00

Short question: Is it possible to do a redirection, say when a user isn’t

  • 0

Short question: Is it possible to do a redirection, say when a user isn’t logged in, when a page is rendered?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:18:51+00:00Added an answer on May 13, 2026 at 11:18 pm

    For that you should use a Filter.

    E.g.

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { 
        if (((HttpServletRequest) request).getSession().getAttribute("user") == null) {
            ((HttpServletResponse) response).sendRedirect("error.jsf"); // Not logged in, so redirect to error page.
        } else {
            chain.doFilter(request, response); // Logged in, so just continue.
        }
    }
    

    Here I assume that the User is been placed in the session scope as you would normally expect. It can be a session scoped JSF managed bean with the name user.

    A navigation rule is not applicable as there’s no means of a “bean action” during a normal GET request. Also doing a redirect when the managed bean is about to be constructed ain’t gong to work, because when a managed bean is to be constructed during a normal GET request, the response has already started to render and that’s a point of no return (it would only produce IllegalStateException: response already committed). A PhaseListener is cumbersome and overwhelming as you actually don’t need to listen on any of the JSF phases. You just want to listen on “plain” HTTP requests and the presence of a certain object in the session scope. For that a Filter is perfect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really short question: Is it possible to communicate/use USB devices on
Short question : is it possible (on an x64 OS of course) ? If
The short question: how can I (or is it possible to) make use of
I've got a pretty short question. Is it possible to initialize a hash with
Short question . How is it possible to execute servlet filters before any declarative
A short question for the PROs. Is it possible to use Zend_Auth_Adapter_DbTable with ZendX_Db_Adapter?
Short Question Is it possible to call a module as retrieved from the python
I have a short question: How is it possible to convert a String, containing
I didn’t found short form for this question as subject… Is it possible to
Possible Duplicate: Are PHP short tags acceptable to use? I have a question using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.