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

  • SEARCH
  • Home
  • 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 1088507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:04:45+00:00 2026-05-16T23:04:45+00:00

The following servlet filter is getting called, but not able to give the correct

  • 0

The following servlet filter is getting called, but not able to give the correct response.
I just looping inside the filter itself. The Browser says,

The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

ExpenseAuthenticationFilter.class

public class ExpenseAuthenticationFilter implements Filter {
public ExpenseAuthenticationFilter() {
    // TODO Auto-generated constructor stub
}

public void destroy() {
    // TODO Auto-generated method stub
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    try
    {
        HttpSession session = ((HttpServletRequest)request).getSession(false);

        if (session == null){
            System.out.println("Inside login Filter");
            ((HttpServletResponse) response).sendRedirect("ExpenseManagementLogin.html");
        }
    }
    catch (IllegalStateException ise){
        System.out.println("Session Not Yet Created");
    }

    chain.doFilter(request, response);
}
public void init(FilterConfig fConfig) throws ServletException {
    // TODO Auto-generated method stub
}

 }

ExpenseAuthentication.class

public class ExpenseAuthentication implements Filter {
public ExpenseAuthentication() {
    // TODO Auto-generated constructor stub
}

public void destroy() {
    // TODO Auto-generated method stub
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException, IllegalStateException{
    try
    {
        HttpSession session = ((HttpServletRequest) request).getSession(false);
        if (session == null ){
            System.out.println("Management Filter");
            ((HttpServletResponse) response).sendRedirect("ExpenseManagementLogin.html");
        }

    }
    catch (IllegalStateException ise){
        System.out.println("Session Not Yet Created");
    }
    chain.doFilter(request, response);
}
public void init(FilterConfig fConfig) throws ServletException {
    // TODO Auto-generated method stub
}

 }

The Web.xml

<filter>
    <filter-name>ExpenseAuthentication</filter-name>
    <filter-class>com.pricar.hibernate.ExpenseAuthentication</filter-class>
</filter>
<filter-mapping>
    <filter-name>ExpenseAuthentication</filter-name>
    <url-pattern>*/ExpenseDetailsManagement.html</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>ExpenseAuthenticationFilter</filter-name>
    <url-pattern>*/ExpenseManagementLogin.html</url-pattern>
</filter-mapping>

The Console Log for “http://localhost:8080/Hibernate/ExpenseDetailsManagement.html&#8221; is

Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter
Inside login Filter

Its not actually going into ExpenseAuthentication.class, But it goes to ExpenseAuthenticationFilter.class and loops inside of it.

Any suggestions!!

Thanks!

  • 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-16T23:04:45+00:00Added an answer on May 16, 2026 at 11:04 pm

    When you do this :

    ((HttpServletResponse) response).sendRedirect("ExpenseManagementLogin.html");
    

    you’re sending the user right to the “ExpenseManagementLogin.html” page which is filtered with ExpenseAuthenticationFilter.

    Here is your infinite loop.

    As long as the user doesn’t have a session it will loop. And as the filter is looping right to itself there won’t be any session.
    Same thing with your second filter. If a filter does a sendRedirect to a path that need to be filtered by itself. Unless you have some controls (here a session creation), you’ll have an infinite loop.

    As this filter only works on “ExpenseManagementLogin.html”, why do you do this redirection ?

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

Sidebar

Related Questions

I created a Servlet filter with the following code in doFilter: HttpServletResponse httpResponse =
I've a Servlet filter which performs the following type cast: HttpServletRequest httpRequest = (HttpServletRequest)
How can I use a Servlet Filter to change an incoming URL from http://nm-java.appspot.com/Check_License/Dir_My_App/Dir_ABC/My_Obj_123
I'd like to use the following filter to open and close persistence managers. public
I have the following action servlet and was wondering if I should create a
I want to do the following: Make a servlet which would sit in a
I have servlet that does the following: public class LoginServlet extends HttpServlet { protected
Following on from my recent question on Large, Complex Objects as a Web Service
Following my question regarding a .NET YAML Library ... as there doesn't seem to
Following this question: Good crash reporting library in c# Is there any library like

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.