zoukankan      html  css  js  c++  java
  • spring入门(八) spring mvc设置默认首页

    1.web.xml配置如下

     1 <!DOCTYPE web-app PUBLIC
     2         "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     3         "http://java.sun.com/dtd/web-app_2_3.dtd" >
     4 
     5 <web-app version="2.4"
     6          xmlns="http://java.sun.com/xml/ns/j2ee"
     7          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     8          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
     9         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    10     <display-name>www.xrelz.com</display-name>
    11 
    12     <!--解决中文乱码的问题-->
    13     <filter>
    14         <filter-name>encodingFilter</filter-name>
    15         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    16         <init-param>
    17             <param-name>encoding</param-name>
    18             <param-value>UTF-8</param-value>
    19         </init-param>
    20         <init-param>
    21             <param-name>forceEncoding</param-name>
    22             <param-value>true</param-value>
    23         </init-param>
    24     </filter>
    25     <filter-mapping>
    26         <filter-name>encodingFilter</filter-name>
    27         <url-pattern>/*</url-pattern>
    28     </filter-mapping>
    29 
    30     <!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
    31     <servlet>
    32         <servlet-name>springmvc</servlet-name>
    33         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    34         <init-param>
    35             <param-name>contextConfigLocation</param-name>
    36             <param-value>classpath:springmvc-config.xml</param-value>
    37         </init-param>
    38         <!-- <load-on-startup>1</load-on-startup> -->
    39     </servlet>
    40 
    41     <servlet-mapping>
    42         <servlet-name>springmvc</servlet-name>
    43         <url-pattern>/</url-pattern>
    44     </servlet-mapping>
    45     <servlet-mapping>
    46         <servlet-name>springmvc</servlet-name>
    47         <url-pattern>/index</url-pattern>
    48     </servlet-mapping>
    49 
    50     <welcome-file-list>
    51         <welcome-file>index</welcome-file>
    52     </welcome-file-list>
    53 </web-app>

    关键是41-52行

    2.控制器controller

    要有对应的  @RequestMapping("/index")  即可.

    3.如何直接通过域名访问

    如果要发布到服务器,不带项目名访问,把项目打包成ROOT.war,放到webapps下即可. ROOT里面直接是资源文件和WEB-INF(不带项目文件夹).

  • 相关阅读:
    进程DLL注入
    静态链接库LIB
    利用MoveFileEx实现程序的隐藏、自启动与自删除
    QueueUserApc实现DLL注入的测试
    简单说说SSDT
    ural 1521. War Games 2 约瑟夫环 SBT实现
    次小生成树 (附:poj1679)
    hoj 1138 LC Display
    hoj 3029 Dictionary 模拟队列
    hoj 2578 Super_Stack 模拟栈
  • 原文地址:https://www.cnblogs.com/ICE_Inspire/p/9801210.html
Copyright © 2011-2022 走看看