springMVC学习笔记-环境配置

来源:互联网 发布:成都app软件开发 编辑:程序博客网 时间:2024/06/05 11:30

1.springMVC-server.XML配置

<?xml version="1.0" encoding="UTF-8"?>  

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
    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.0.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-3.0.xsd">
   
<bean name="/test/hello" class="com.tgb.web.controller.HelloWordController"></bean>

<!-- 视图分解器   把视图进行分解-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- prefix前置  也就是在什么目录下生效 -->
<!-- suffix  后缀 -->
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>

</beans>


2.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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name></display-name>
  <welcome-file-list>
    <welcome-file>hello.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*:config/springMVC-servlet.xml</param-value>
</init-param>


<!-- 启动设置     什么时候启动    1代表服务器一启动,就随着启动-->
<load-on-startup>1</load-on-startup>
  </servlet>
  
  <!-- 拦截请求 -->
  <servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>



0 0
原创粉丝点击