Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the SpringMVC xml file path in web.xml

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to configure SpringMVC xml file path in web.xml". In daily operation, I believe many people have doubts about how to configure SpringMVC xml file path in web.xml. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "how to configure SpringMVC xml file path in web.xml". Next, please follow the editor to study!

Catalogue

Configuration of SpringMVC xml File path in web.xml

SpringMVC modifies the profile path

1.1.Classpath

1.2.Classpath *

What is 1.3.Classpath?

The difference between 1.4.Classpath and classpath*

Configuration of SpringMVC xml File path in web.xml

Under normal circumstances, the xml file of springmvc should be placed under WEB-INF, the naming rule is [name]-servlet.xml, "- servlet" this field is essential [name] you can name it freely, at the same time, the two servlet in your web.xml file should be the same as your name, or you will report an error.

File path configuration of springmvc-servlet.xml in web.xml

If you put it in the src directory, you need to configure the springmvc-servlet.xml path manually, the naming is no longer restricted, the file path is correct and the two are the same. File path configuration of springmvc-servlet.xml in web.xml

Note: the current path on the author's computer is under resources. You can pass ". /" to test where the current path is.

SpringMVC modifies the configuration file path 1.1.Classpath

Engineering catalogue

Configure the following in the web.xml file:

Spring org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:config/spring-servlet.xml 1 spring * .Classpath1.2.Classpath *

The project catalogue is the same as above.

The configuration in the Web.xml file is as follows:

What is spring org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath*:config/spring-servlet.xml 1 spring * .do 1.3.Classpath

The purpose of setting up Classpath is to tell the Java execution environment in which directories you can find the classes or packages needed by the Java program you want to execute.

Classpath refers to the classes directory under the WEB-INF folder. When the web application is published to the server, the compiled class files and resource files of all the classes under the src directory will be placed into the classes directory under the WEB-INF folder.

The difference between 1.4.Classpath and classpath*

Classpath: only look for files in your class path.

Classpath*: contains not only the class path, but also the jar file (class path) for lookup.

1) the former will only be loaded from the first classpath, while the latter will be loaded from all classpath.

2) if the resource to be loaded is not in the current ClassLoader path, the classpath: prefix cannot be found, in which case you need to use the classpath*: prefix.

3) if a resource of the same name exists in multiple classpath and needs to be loaded, then using classpath: only the first one will be loaded, in which case you also need to use the classpath*: prefix.

4) using classpath*: needs to traverse all the classpath, so the loading speed is very slow, so when planning, you should plan the path where the resource file is located as well as possible and avoid using classpath* as much as possible.

At this point, the study on "how to configure the path of SpringMVC xml files in web.xml" 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report