john Smith
john Smith

Reputation: 1605

Java servlet filter - block all requests from client

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 ?

Upvotes: 0

Views: 3975

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44824

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);

Upvotes: 2

Related Questions