一、问题

在web.xml中添加如下配置无效

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

访问http://localhost/KingWeixin/ 无作用

二、解决问题

2.1、问题分析

.默认tomcat容器的默认页面。 

/index.html 

这种方式适合访问静态的页面(也包括JSP)或者说是没有任何参数的页面。

.spirng mvc 默认index controller 方式
如果在tomcat容器没有配置默认页面,怎spring mvc 会主动去寻找/index的controller,如果有则会调用,没有则会显示404页面。
@RequestMapping(value=”/index”)
public ModelAndView index(HttpServletRequest request, HttpServletResponse response){
return new ModelAndView(“index”);
} .spirng mvc 配置根节点访问“/”方式
这种方法比较极端,就是配置一个名为“/”的controller,就是输入完网址之后就会调用。这种方法是前面两种方法都没有配置的时候。
@RequestMapping(value=”/”) public ModelAndView index(HttpServletRequest request, HttpServletResponse response){ return new ModelAndView(“index”); } 三种方法的级别高低:>>>>;因为tomcat的容器级别比spring要高,以上3钟配置都存在的情况,优先使用tomcat。因为配置了”/”的controller,所以会先匹配到相关的controller,而不会先寻找/index controller. 注意,即使web.xml没有添加,tomcat也会自动默认去寻找在webroot目录下面的index文件,如果要使用后面两种方法,则要保证webroot下面没有index相关的文件。 综合经验,第三种方法最方便 使用方法例如: @RequestMapping("/")
public ModelAndView index(ModelAndView modelAndView, HttpServletRequest request, String openId) {
return new ModelAndView("redirect:/toLogin.do");
} @RequestMapping("/toLogin.do")
public ModelAndView toLogin(ModelAndView modelAndView,Model model, HttpServletRequest request) {
modelAndView.setViewName("index");
return modelAndView;
}

Spring MVC中默认HTML为静态资源,所以我们可以通过设置我们静态资源映射的index.html为项目默认访问的页面

2.2: Spring 设置静态资源映射和目录(切记index.html要放到html目录下)

<mvc:resources mapping="/img/**" location="/img/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/html/**" location="/html/" />
<mvc:resources mapping="/tinymce/**" location="/tinymce/" />
<mvc:resources mapping="/upload/**" location="/upload/" />
<mvc:resources mapping="/assset/**" location="/assset/" />
<mvc:resources mapping="/data/**" location="/data/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/media/**" location="/media/" />

2.3:创建一个跳转到index对象的Controller

/**
*
*/
package com.king.weixin.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author kingstudy@vip.qq.com
* @version 创建时间:2018年6月13日 下午10:28:26
* @ClassName IndexController
* @Description Spring MVC 跳转到首页
*/
@Controller
public class IndexController { @RequestMapping(value="/")
public ModelAndView GoToIndex(HttpServletRequest request, HttpServletResponse response){
return new ModelAndView("index");
} }

2.3:测试localhost/项目名称-配置OK

SpringMVC项目配置欢迎页面为index.html的更多相关文章

  1. shiro+SpringMVC 项目 配置404页面

    说的配置404,大家都会想到去web.xml里面配置 <error-page> <error-code></error-code> <location> ...

  2. SpringMVC项目配置

    一.创建一个maven项目 1.new一个maven项目,选择next,如图:

  3. SpringMvc 项目配置

    spring-mvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&quo ...

  4. 多个SpringMVC项目配置统一管理(来自于springCloud的统一配置思路)

    因公司项目分多个系统进行开发,而系统架构几乎完全一样,所以同样的配置文件会存在不同的系统中 当其中的某些配置需要修改时,就需要依次把所有系统中相关的配置都修改掉 纯耗时且没技术含量的体力活 所以借鉴S ...

  5. 零配置简单搭建SpringMVC 项目

    SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...

  6. SpringMVC 04: SpringMVC中4种页面跳转方式

    转发和重定向的页面跳转方式 页面跳转方式,本质上只有2种方式:转发 + 重定向 但在SpringMVC的具体实现上,转发可以细分为:普通的页面转发 + 经由action方法的页面转发 重定向可以细分为 ...

  7. SpringMVC简单项目配置

    一.首先,SpringMVC框架使用分层开发,分层是为了实现“高内聚,低耦合”.采用“分而治之”的思想,把问题划分开来各个解决,易于控制,延展和分配资源,最重要的是有利于后期项目维护.MVC是指Mod ...

  8. springmvc+spring+mybatis 项目配置

    前提 工作环境:JDK 1.8.Mysql 5.7.18.Intellij IDEA 2018.1.Tomcat 8.5.Maven 框架版本:Spring 4.2.0.RELEASE.SpringM ...

  9. springmvc 项目完整示例06 日志–log4j 参数详细解析 log4j如何配置

    Log4j由三个重要的组件构成: 日志信息的优先级 日志信息的输出目的地 日志信息的输出格式 日志信息的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定这条日志信息的重要程度 ...

随机推荐

  1. CCF2015122消除类游戏(C语言版)

    问题描述 消除类游戏是深受大众欢迎的一种游戏,游戏在一个包含有n行m列的游戏棋盘上进行,棋盘的每一行每一列的方格上放着一个有颜色的棋子,当一行或一列上有连续三个或更多的相同颜色的棋子时,这些棋子都被消 ...

  2. 【splunk】用正则表达式提取字段

    设input输入数据为 http://192.168.23.121/xxx  想提取出里面的ip,可以用rex source="xxx.csv" |rex field=input ...

  3. eclipse 更换主题

    更换系统自带主题 依次点击 window->preferences->General->Appearance->Theme 选择主题 下载eclipse marketplace ...

  4. 使用匿名内部类调用start方法

    package chapter03;//类实现接口public class WD implements Runnable{//重写接口的方法 @Override public void run() { ...

  5. istringstream、ostringstream、stringstream 类介绍 和 stringstream类 clear函数的真正用途

    istringstream.ostringstream.stringstream 类介绍 和 stringstream类 clear函数的真正用途 来源: http://blog.csdn.net/T ...

  6. ***LANMP镜像手册(Apache&Nginx)-lanmp-oneinstack

    LANMP镜像手册(Apache&Nginx) Version PHP7.0.26  转自:http://docs.websoft9.com/xdocs/lanmp-oneinstack-im ...

  7. [转] Optimizely:在线网站A/B测试平台

    Optimizely:在线网站A/B测试平台是一家提供 A/B 测试服务的公司.A/B 测试能够对比不同版本的设计,选取更吸引用户眼球的那一款,从而带来更为优化的个人体验.让网站所有者易于对不同版本的 ...

  8. 【莫比乌斯反演】HDU1695_GCD

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 第一道莫比乌斯反演 感觉很巧妙的就是利用了F(x)=(n/x)*(m/x) 之后的那个去重也挺不 ...

  9. 076 Apache的HBase与cdh的sqoop集成(不建议不同版本之间的集成)

    1.修改sqoop的配资文件 2.从mysql导入到hbase(import) bin/sqoop import \ --connect jdbc:mysql://linux-hadoop3.ibei ...

  10. centos7.2下安装Mysql笔记

    centos7.2下安装Mysql笔记 安装 MySQL 适用于 CentOS 7.0 或以后版本: yum install mariadb mariadb-server 适用于 CentOS 6.8 ...