Erstellen Sie die folgende Klasse
public class RestHttpRequestFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
// if the ServletRequest is an instance of HttpServletRequest
if (servletRequest instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
System.out.println(httpServletRequest.getRequestURL());
if (httpServletRequest.getRequestURL().toString().contains("/user/account")
&& servletRequest.getProtocol().contains("HTTP")) {
throw new ResourceNotFoundException(
"The url should be HTTPS");
}
filterChain.doFilter(httpServletRequest, servletResponse);
} else {
// otherwise, continue on in the chain with the ServletRequest and
// ServletResponse objects
filterChain.doFilter(servletRequest, servletResponse);
}
return;
}
public void init(FilterConfig filterConfig) throws ServletException {}
}
web.xml Eintrag
simpleFilter
RestHttpRequestFilter
simpleFilter
/*
0 Stimmen
Haben Ihre "einige Seiten" ein gemeinsames URL-Muster?
0 Stimmen
N@joseK Die URL-Struktur ist anders.
0 Stimmen
Dieses Thema ähnelt stark stackoverflow.com/questions/1454021/….