In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to write url-pattern in spring mvc". In daily operation, I believe many people have doubts about how to write url-pattern in spring mvc. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to write url-pattern in spring mvc". Next, please follow the editor to study!
1. Set url-pattern to * .do (the most common way)
As long as your request url contains the configured url-pattern, the url can reach the DispatcherServlet. Of course, url-pattern is usually configured as * .do in the industry here, so you'd better do the same.
two。 Set url-pattern to / * (this is a very bad way)
If url-pattern is set to / *, none of the jsp in the web project will report an error of 404, because DispatcherServlet will treat the jump request to the JSP page as a normal Controller request, and can not find the corresponding controller at this time.
3. Set url-pattern to / (used more and more)
If url-pattern is set to /, as long as a matching URL is not found in the web.xml file, their access requests will be handed over to DispatcherServlet for processing, static resources: css files, js files, images will also be intercepted and handed over to DispatcherServlet for processing. This configuration does not intercept .jsp files and .jspx files, because the corresponding processing that has been added to the web.xml file in the conf directory in tomcat will be handed over to org.apache.jasper.servlet.JspServlet. That is, we can access the jsp file in the system normally.
There are three ways to solve the problem that static resources cannot be accessed:
Use defaultServlet
We can use this DefaultServlet to deal with static resources by adding the following configuration to the web.xml file in your system, before the DispatcherServlet, so that the system will hand over the request with the following suffix to defaultservlet for processing:
Default * .jpg default * .png default * .js default * .css
Use mvc:default-servlet-handler
Use mvc:resources
The mvc:resources tag is provided in springmvc to solve the problem that static resources cannot be accessed. Just add the following to the configuration file of springmvc.xml, which will be handled by the ResourceHttpRequestHandler class of springmvc:
Where:
Mapping represents a request for the resource. Notice that it is followed by two asterisks.
Location represents the directory where the static resources are located. In my project, create an images folder under webapp and put all the images in this folder.
At this point, the study of "how to write url-pattern in spring mvc" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.