springMVC.xml和web.xml配置文件

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>RestEmp</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <!-- 编码过滤器 -->
  <filter>
  	<filter-name>CharcterEncodingFilter</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>CharcterEncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <filter>
  	<filter-name>HiddenHttpMethodFilter</filter-name>
  	<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>HiddenHttpMethodFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
  
   <!-- 核心控制器 -->
  <servlet>
  	<servlet-name>springMVC</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  	<servlet-name>springMVC</servlet-name>
  	<url-pattern>/</url-pattern><!-- 这里建议用/,而不是/* -->
  </servlet-mapping>
  
</web-app>
``
springMVC.xml

```xml
<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:mvc="http://www.springframework.org/schema/mvc"
		xmlns:p="http://www.springframework.org/schema/p"
		xmlns:context="http://www.springframework.org/schema/context"
		xsi:schemaLocation="
        	http://www.springframework.org/schema/beans
        	http://www.springframework.org/schema/beans/spring-beans.xsd
        	http://www.springframework.org/schema/context
        	http://www.springframework.org/schema/context/spring-context.xsd
			http://www.springframework.org/schema/mvc
        	http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        	
	<!-- 配置组件扫描,将@Controller注解的类作为springMVC的控制层 -->
	<context:component-scan base-package="com.atguigu.rest.curd"></context:component-scan>
	
	<!-- 配置视图解析器 -->
	<!-- 作用:将prefix+视图名称+suffix确定最终要跳转的页面
				 /WEB-INF/view/success.jsp-->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/view/"></property><!--视图层地址-->
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	 <!-- 处理静态资源 -->
	 <!-- 配置tomcat中默认的servlet,DefalutServlet
		注意,当DefalutServlet所设置的<url-pattern>的值和开发人员所配置的DispatcherServlet的<url-pattern>相同时,以开发人员所配置优先
	 	作用:当客户端发送请求,由于开发人员设置的配置的<url-pattern>也是/
	 	因此先通过DispatcherServlet来处理请求,找该请求是否有相对应的处理器,有则处理,无则交给DefalutServlet处理
	 -->
	<mvc:default-servlet-handler />
	<!-- mvc驱动 -->	
	<mvc:annotation-driven />
	
	
</beans>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值