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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:24:10+00:00 2026-06-05T05:24:10+00:00

I have a problem with redirection – it simply does not work for valid

  • 0

I have a problem with redirection – it simply does not work for valid paths.
Right now I use page forwarding in the Servlet, but I need redirection in a filter.

All the pages reside in the ‘pages’ folder and have a .jspx extension

I’ve tried the following (this path works with forwarding):

httpResponse.sendRedirect("/pages/login.jspx");

browser url is http://[localhost]/pages/login.jspx, and it shows Tomcat’s 404 page, the context path (in my case it’s ‘/hotel’) is missing from the url, so, if I add it:

httpResponse.sendRedirect("/hotel/pages/login.jspx");

redirect does not happen, browser url does not change, and I’m shown the browser’s 404 page (This program cannot display the webpage).

What am I doing wrong?

The filter which is used to test this has the following mapping:

@WebFilter(filterName = "SecurityFilter", urlPatterns = "/*")
  • 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-06-05T05:24:11+00:00Added an answer on June 5, 2026 at 5:24 am

    The redirected URL is indeed relative to the initially requested URL. To dynamically prepend the context path it’s recommended to use HttpServletRequest#getContextPath() instead of hardcoding it, because the context path value can be changed externally by server-specific configuration.

    As to your concrete problem, I’m not sure if I understand “browser’s 404 page” properly, perhaps you mean the browser-default error page which can occur when the server is unreachable or when the request has been redirected in an infinite loop (that should however have been made clear in the actual message of the browser default error page, at least Chrome and Firefox do that).

    Given that your filter is mapped on /*, it’s actually redirecting in an infinite loop because the request URL of the login page in turn also matches the URL pattern of the filter.

    You’d need either to put the filter on a more specific URL pattern which does not cover the login page, e.g. on /secured/* where all restricted pages are been moved in there (or map it on /pages/* and put the login page outside there), or to fix your filter as follows:

    String loginURL = request.getContextPath() + "/pages/login.jspx";
    
    if (needsToRedirect && !request.getRequestURI().equals(loginURL)) {
        response.sendRedirect(loginURL);
    }
    else {
        chain.doFilter(request, response);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with .NET assembly redirection. 3rd party assembly A references another
I have an odd problem. I have a page called search.aspx. When the search
Have a very strange problem with Apache .htaccess URL Rewriting and Redirection. Here's my
I have a problem with my role redirection. Why my code { if (Roles.IsUserInRole(Login1.UserName,
hi all i have a redirection problem with mod ajp, that it always adds
I have an issue I'm having trouble :/ err404 page's 200OK header status problem,
Greetings, Here's the problem I'm having. I have a page which redirects directly to
I have a problem redirecting a folder to another one. The rule seems to
I have problem with consuming DbContext class in EF 4.3 CodeFirst approach. As for
I have problem with building in Qt4 creator. I have some created projects and

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.