zoukankan      html  css  js  c++  java
  • 第一个spring MVC

    1、导包

    Spring所有包

    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" 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>springMVC</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springServlet.xml</param-value>
        </context-param>
    
        <servlet>
            <servlet-name>springServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value></param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>springServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>
    

    3、springServlet.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"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        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-4.1.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">                    
    
        <!-- scan the package and the sub package -->
        <context:component-scan base-package="com.sysker"/>
    
        <!-- don't handle the static resource -->
        <mvc:default-servlet-handler />
    
        <!-- if you use annotation you must configure following setting -->
        <mvc:annotation-driven />
        
        <!-- configure the InternalResourceViewResolver -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
                id="internalResourceViewResolver">
            <!-- 前缀 -->
            <property name="prefix" value="/WEB-INF/view/" />
            <!-- 后缀 -->
            <property name="suffix" value=".jsp" />
        </bean>
    </beans>
    

    4、servlet文件

    package com.sysker.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    @RequestMapping("/spring")
    public class SpringServlet {
        @RequestMapping("/index")
        public String index() {
            return "index";
        }
    }
    
    
  • 相关阅读:
    ubuntu16.04下docker安装和简单使用(转)
    spring security There was an unexpected error (type=Forbidden, status=403).
    笔记42 Spring Web Flow——Demo(2)
    Idea debug时报错:Command line is too long
    特殊字符(包括emoji)梳理和UTF8编码解码原理(转)
    如何理解多租户架构?(转)
    Android Studio使用阿里云Aliyun Maven仓库
    解决 INSTALL FAILED CONFLICTING PROVIDER
    Android解决冲突
    Mysql查询库、表存储量(Size)
  • 原文地址:https://www.cnblogs.com/caoleiCoding/p/9256209.html
Copyright © 2011-2022 走看看