码迷,mamicode.com
首页 > 编程语言 > 详细

springMVC配置

时间:2014-11-05 15:13:49      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   os   java   sp   文件   on   2014   

第一步:导入相关jar包。

bubuko.com,布布扣

第二步:springMVC配置文件配置,以spring-servlet.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:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
    <!-- 启用spring-mvc 注解 -->
    <context:annotation-config />
 
    <!-- 扫描controller包 -->
    <context:component-scan base-package="com.holleyinfo.controller"/>
 
    <!-- 配置视图解析器。prefix:前缀, suffix:后缀 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	<property name="prefix" value="/"/>
    	<property name="suffix" value=".jsp"></property>
    </bean>
</beans>

第三步: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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>spring-test</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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-servlet.xml</param-value>
  	</init-param>
  	<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  	<servlet-name>springMVC</servlet-name>
  	<url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>


springMVC配置

标签:http   io   ar   os   java   sp   文件   on   2014   

原文地址:http://my.oschina.net/u/1469821/blog/341007

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!