P
P
parkito2016-08-27 02:04:32
Java
parkito, 2016-08-27 02:04:32

How to change query parameter in Filter?

Hello. I have a task in the filter to change the request sent to the servlet. Please advise how this can be done.

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

        request.setAttribute("param", "Hello");
        
        HttpServletRequest req = (HttpServletRequest) request;
        System.out.println(req.getParameter("param"));
        RequestDispatcher dispatcher = request.getRequestDispatcher("/");
        dispatcher.forward(request, response);
        chain.doFilter(request, response);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Kozak, 2016-09-01
@McKey92

  1. In this situation, there is no need to call dispatcher.forward(request, response);
    Should help!)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question