0

I want to block all requests from client at some point, meaning any request that the server receive a filter will not forward it and stop the chain, So the user will stay on the current page.

how can I achieve that ?

0

1 Answer 1

2

Just either add a return statement to the end of the if

if (sn.startsWith("www.")) {
    String url = "http://" + getDefaultDomain() + req.getContextPath() + req.getRequestURI();
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.reset();
    resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    resp.setHeader("Location", url);
    return;
}
chain.doFilter(request, response);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the replay but from reading your code I'm assume you are doing forward to the requested URL.. because url is taken from the request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.