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 224301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:18:14+00:00 2026-05-11T19:18:14+00:00

I have a servlet filter that handles errors for both vanilla servlets and JSF

  • 0

I have a servlet filter that handles errors for both vanilla servlets and JSF pages.

If an error is detected the user is redirected to an error page where he can give feedback. Then I try to read the value in the ErrorBean object. However, sometimes the error is not present – there is a 50-50 chance of the error being present.

When I use

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()

it sometimes returns a map with 1 entry and sometimes an empty map. In every case, the id is passed at http level.

I can’t really reproduce what is causing this. Here is the relevant code (helper methods + empty implementations omitted). The ErrorFilter is mapped at /* and the ErrorBean is a session scope bean managed by JSF.

ErrorFilter

public class ErrorFilter implements Filter 
{
  public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException 
  {
    HttpServletRequest hreq = (HttpServletRequest) req;
    HttpServletResponse hres = (HttpServletResponse) resp;

    try 
    {
      chain.doFilter(req, resp);
    } 
    catch (IOException e) 
    {
      handleError(e, hreq, hres);
    } 
    catch (ServletException e) 
    {
      handleError(e, hreq, hres);
    } 
    catch (RuntimeException e) 
    {
      handleError(e, hreq, hres);
    }
  }

  private static void handleError(Throwable e, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
  {
    final RequestInfo requestInfo = new RequestInfo(getUri(req), req.getSession().getId(), null, null, UserFactory.getUser(), InetAddress.getByName(req.getRemoteAddr()));
    String token = new DecimalFormat("00000000").format(Math.abs(RANDOM.nextInt() % Integer.MAX_VALUE));
    //log msg
    //send mail in a different thread

    if (!req.getRequestURI().startsWith("/faces/error.jsp")) 
    {
      resp.sendRedirect("/faces/error.jsp?token=" + token);
    } 
    else 
    {
      //log that an infite loop occurred
      throw new ServletException(crapMsg, e);
    }
  }
}

ErrorBean

public class ErrorBean implements Serializable 
{
  private String feedback;
  private String lastToken;

  public String getLastErrorCode() 
  {
    return "your token: " + getToken();
  }

  private String getToken() 
  {
    final String token = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("token");
    //here the "token" returns null although it is sent via get.

    if (token != null) 
    {
        if (!token.equals(lastToken)) 
        {
          // reset data on token change.
          feedback = null;
        }
        lastToken = token;
    }

    return lastToken;
  }

  public void setFeedback(String feedback) 
  {
    this.feedback = feedback;
  }

    public String getFeedback() 
    {
      if (feedback == null) 
      {
        feedback = getDefaultMessage();
      }

      return feedback;
    }

  public void send()
  {
    sendMail(lastToken,feedback);
  }
}
  • 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-11T19:18:14+00:00Added an answer on May 11, 2026 at 7:18 pm

    From my humble point of view, The faces Context should see the parameter the vary first time when request is already redirected on : resp.sendRedirect("/faces/error.jsp?token=" + token);

    But when you make some other request, Faces do manipulation with it’s Navigation system and Redirect the page, and obviously that the Filter is doing chain.doFilter(req,resp); that time, which authorize the JSF Navigation model to execute and thus removing your request parameter.

    My suggestion is that you can add it to another session value, It’ll be easier to manipulate then.

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

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Don't you want a ListProperty on Task like this to… May 11, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer Building off Carlos there: path = "/controllername/action/whatever" c_name = ActionController::Routing::Routes.recognize_path(path)[:controller]… May 11, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer You would not generally need to do anything to Apache… May 11, 2026 at 10:30 pm

Related Questions

I am quite new to ICEfaces but already have experience with JSF/Facelets and the
I have run into an issue in which IE does not open up the
I have a Tapestry application that is serving its page as UTF-8. That is,
we have a J2EE web application usig Spring MVC. We have a new requirement
I don't know, but I feel that IllegalStateException is causing undo headache. If I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.