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

The Archive Base Latest Questions

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

I need to forward my request (to a jsp but I don’t think it’s

  • 0

I need to forward my request (to a jsp but I don’t think it’s matter) from an http.Filter
if the URI of the original request pass some validation that my filter runs.

I found this page that faced similar task

Still I need to figure the following:

  1. How can I get ServletContext in doFilter() method (in order to call forward API) getServletContext() is not recignized

  2. Do I have to call chain.doFilter() before the forward, after the forward or not at all?
    In addition do I have to call chain.doFilter() if my validation passed or only if it fails (because in this case I won’t continue to forward my page)?

This question actually continue this thread,
to be more obvious, the code could be something like:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if (request instanceof HttpServletRequest) {
            HttpServletRequest httpServletRequest = ((HttpServletRequest)request);
            String requestURI = httpServletRequest.getRequestURI();
            String contextPath = httpServletRequest.getContextPath();
            if (<this is my implementation of the validation of this filter>){                                      
                getServletContext().getRequestDispatcher(
                "MySpecific.jsp").forward(request,response);

            }

        }
        chain.doFilter(request,response);

    }
  • 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-16T02:40:05+00:00Added an answer on May 16, 2026 at 2:40 am

    How can I get ServletContext in doFilter() method?

    httpServletRequest.getSession().getServletContext();
    

    Do I have to call chain.doFilter() before the forward, after the forward or not at all? In addition do I have to call chain.doFilter() if my validation passed or only if it fails (because in this case I won’t continue to forward my page)?

    I would say that if you forwarded the request, you should not call chain.doFilter() – the forwarded request will get filtered according to its own filter configuration. If your validation failed though, it depends on what the semantics of your web app are – if the original page is some sort of general error/login/welcome screen, you may want to continue to that when the validation failed. It is hard to say without knowing more of the context.

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

Sidebar

Related Questions

I need to pass a variable from Admin.java file to index.jsp. I get the
I am trying to forward my request from a Spring-MVC controller method - to
We are using Struts 2 Dispatcher Result to forward our request to some jsp
I want to forward request to a non-JSF page from JSF action method. I
In my jsp file I am pulling data from the request via request.getAttribute() .
I need to display the data from a servlet in a jsp page. At
I'm created an hpp file and I need to forward declare classes as I
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
I need some advice on how I am using JQuery, JSP and Lucene to
I am exposing a CXF service using Mule ESB and i need to pass

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.