springmvc基本web.xml配置和xxxx-sevlet.xml配置简介
2014-12-07 21:39
495 查看
web.xml配置
???-servlet.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_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>spring_mvc</display-name> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 自己定义servlet.xml位置 --> <!-- classpath*:表示项目根目录,可以自己修改xxx-servlet.xml的位置 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup><!-- 启动服务器时就创建DispatcherServlet --> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 字符过滤器 --> <!-- org.springframework.web.filter.CharacterEncodingFilter是SpringMVC自带的字符过滤器 --> <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> </web-app>
???-servlet.xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- 注解扫描 --> <context:component-scan base-package="controller" /><!-- 你的controller放在哪个目录包下(我的目录是controller),base-package就改为什么 --> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/jsp/" /> <!-- 前缀:表示访问的jsp文件时的目录 --> <property name="suffix" value=".jsp" /><!-- 后缀:表示文件类型 --> </bean> <!-- 注解驱动 --> <mvc:annotation-driven/><!-- 没有它注解就无法使用 --> <!-- mapping:访问的路径 --> <!-- 当你访问一些资源文件时(js,css时),你不希望这些文件被DispatcherServlet拦截,所以要配置 --> <mvc:resources mapping="/resource/*" location="/resource/"/> <mvc:default-servlet-handler/> <!-- 请求分发器配置 --> <!-- 这是不适用注解时的配置 ,比较麻烦,需要自己配置请求名和对应的controller,当有很多请求时会要写很多这些文件--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/test.do">myController</prop> </props></property> </bean> <bean id="myController" class="controller.MyController"></bean> </beans>
相关文章推荐
- SpringMVC之web.xml基本配置
- springmvc 项目:web.xml基本配置
- springmvc 项目:web.xml基本配置
- web.xml文件的作用及基本配置
- web.xml文件的作用和基本配置
- web.xml文件的作用及基本配置
- struts2在web.xml中的基本配置
- JavaWeb工程中web.xml基本配置
- jsp web.xml文件的作用及基本配置
- web.xml配置简介
- 理解Struts在web.xml中的基本配置
- Ajax框架 DWR 简介(3)---配置web.xml文件
- web.xml文件的作用及基本配置
- web.xml文件的作用及基本配置
- web.xml文件的作用及基本配置
- web.xml文件的作用及基本配置
- jsp web.xml文件的作用及基本配置
- web.xml文件基本配置讲解
- jsp web.xml文件的作用及基本配置
- springmvc之web.xml配置