1.报错如图所示
2.解决方案:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 前端控制器 -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern><!-- url匹配模式 -->
</servlet-mapping>
<!-- SprinMVC提供的字符编码过虑器 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 因为被前面的 前端端控制器,SprinMVC提供的字符编码过虑器拦截了,所以要配置(匹配)的所有js文件 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
3.
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="3.0" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 6 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 7 <display-name></display-name> 8 9 <context-param> 10 <param-name>contextConfigLocation</param-name> 11 <param-value>classpath:applicationContext.xml</param-value> 12 </context-param> 13 <listener> 14 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 15 </listener> 16 17 18 <!-- 请求监听 --> 19 <!-- <listener> 20 <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 21 </listener> --> 22 23 <!-- 前端控制器 --> 24 <servlet> 25 <servlet-name>dispatcher</servlet-name> 26 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 27 <load-on-startup>1</load-on-startup> 28 </servlet> 29 <servlet-mapping> 30 <servlet-name>dispatcher</servlet-name> 31 <url-pattern>/</url-pattern><!-- url匹配模式 --> 32 </servlet-mapping> 33 34 35 36 <!-- SprinMVC提供的字符编码过虑器 --> 37 <filter> 38 <filter-name>characterEncodingFilter</filter-name> 39 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 40 <init-param> 41 <param-name>encoding</param-name> 42 <param-value>UTF-8</param-value> 43 </init-param> 44 </filter> 45 <filter-mapping> 46 <filter-name>characterEncodingFilter</filter-name> 47 <url-pattern>/*</url-pattern> 48 </filter-mapping> 49 50 <!-- 因为被前面的 前端端控制器,SprinMVC提供的字符编码过虑器拦截了,所以要配置(匹配)的所有js文件 --> 51 <servlet-mapping> 52 <servlet-name>default</servlet-name> 53 <url-pattern>*.js</url-pattern> 54 </servlet-mapping> 55 56 57 <welcome-file-list> 58 <welcome-file>index.jsp</welcome-file> 59 </welcome-file-list> 60 </web-app>