1:我先建立了个web项目,
(1)在pom.xml中添加了如下
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
(2)在web.xml中添加了
<filter>
<filter-name>encoding</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>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
就报错,说是项目不认识filter过滤器,项目也一直出现小红叉,网上说右键点击项目,然后依照https://blog.csdn.net/qq_25313187/article/details/75041965来做就可以了。但是我点击后并未出现maven denpendenciies.....网上说我右键项目名,点击maven --》update object就可以了,我尝试后依然无果,最终才知道,原来我在pom.xml中需要添加<properties>来配置 <version>${spring.version}</version>中的属性·。
2:配好过滤器,我开始写了个servert的映射,配置了一个最简单的servlet的class,run as后项目是可以运行的,于是我在web.xml中配置分发器
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.wth</url-pattern>
</servlet-mapping>
发现报错,说未从ServletContext resource中识别到 [/WEB-INF/springmvc-servlet.xml],网上查说是因为需要把web.xml和applicationContext.xml两个文件放在一起,那么我就把applicationContext.xml用参数加了进来,https://blog.csdn.net/zheng911209/article/details/51242525,init是不行的,必须context中做
原文地址:https://www.cnblogs.com/wth21-1314/p/9615022.html