spring mvc 初记1

spring mvc 小记1

一,web.xml  配置

<!--spring mvc -->  
<servlet> 
   <servlet-name>mvc</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-servlet-scan.xml</param-value>
        </init-param>
    <load-on-startup>1</load-on-startup>
    
</servlet> 
<servlet-mapping> 
    <servlet-name>mvc</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

 

二,mvc-servlet-scan.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
   >
  
       
        <!--过滤静态资源文件   -->
       
        <mvc:resources mapping="*.js"    location="/aos-mine/media/**/**"/> 
        <mvc:resources mapping="*.html"  location="/aos-mine/portal/**/**"/> 
        <mvc:resources mapping="*.css"   location="/aos-mine/media/**/**"/> 
        <mvc:resources mapping="*.jpg"   location="/aos-mine/media/**/**"/> 
        <mvc:default-servlet-handler />
  
  
    <!--   可以省略此配置,如果配置了 context:component-scan 下面。
    <context:annotation-config />
    -->
    <context:component-scan base-package="com.zte.mine.handler"/>
 
    <!-- ViewResolver -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/portal/" />
        <property name="suffix" value=".jsp" />
    </bean>
 
</beans>

 

3,控制类

/**
 *
 *
 * @author
 */

@Controller
@RequestMapping(value="/test")
public class LoginController {

    @RequestMapping(value = "/login")
    public String login() {
       
        return "MyJsp";
    }
   
    @RequestMapping(value = "/login2")
    public String login2() {
       
        return "MyJsp";
    }

}