First web.xml configuration


url-pattern configuration /, you can ask if you configure/*,Even the return view jsp will intercept,See the source for specific reasons

Question:If configured in this way,Everyone will ignore a problem,Is a/b/c accessible,But a/b/c.do;a/b/c.mm;a/b/c.zz can access the a/b/c controller. Without modifying the source code,Let's

solve this problem,Although all intercepted/such requests,But we only let requests such as a/b/c enter the controller, and those with a suffix of [.] Are not allowed to enter.Go directly to the 404 page


web.xml join filte

<!-Simple filtering on urls->
import java.io.ioexception;
import javax.servlet.filterchain;
import javax.servlet.servletexception;
import javax.servlet.http.httpservletrequest;
import javax.servlet.http.httpservletresponse;
import org.springframework.web.filter.onceperrequestfilter;
* Process incoming URLs,Put in front of the filter, springmvc<url-pattern>/</url-pattern>
* Block all requests by default,ex:a/b/c.do, a/b/c.html, a/b/c.action, a/b/c
* Remove suffixed visits,Imitating restful style, only accepting a/b/c requests
* /
public class servletrequestfilter extends onceperrequestfilter {
protected void dofilterinternal (httpservletrequest request,httpservletresponse response, filterchain filterchain)
throws servletexception, ioexception {
string requestpath=request.getservletpath ();
//Don't worry about blocking the static files,For example * .js, * .css is similar to this,Processed in web.xml
//All requests with the suffix [.] Go directly to 404, such requests are not accepted
if (requestpath.lastindexof (".")! =-1) {
request.getrequestdispatcher ("/web-inf/pages/error/404.jsp"). forward (request, response);
} else {
filterchain.dofilter (request, response);

Direct go 404 with. Ending, haha, maybe you will ask if this static file will also be filtered out?Similar to * .js, * .css, ..... n many files of this type

  • Previous Summary of Bootstrap's most commonly used JS plugin series (picture carousel, tag switching, etc)
  • Next Graphic explanation of PHP environment building tutorial