spingmvc项目根路径访问不到
问题: 如何改mvc中项目的欢迎页,或者叫做根路径
一个东西快弄完了,就剩下一个问题,应该是个小问题。就是mvc项目的欢迎页,怎么给改下呢
访问根路径http://localhost/demo 怎么都访问不到webapp下index.html
让其跳转到http://localhost:8080/demo/index
1. 缺省的流程
先看看缺省的根路径流程:
web.xml 中什么没有配置任何有关欢迎页的信息!其实这时等效于如下配置:这个会由Web容器最先访问!
欢迎页配置 <welcome-file-list> <welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> servlet拦截配置 <servlet>
<servlet-name>demo-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>demo-servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
而项目目录下,有个index.html文件,进行了跳转:
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=index/">
</head>
</html>
按照上面的配置,使用jetty服务器没有生效,http://localhost/demo访问不到根目录下index.html
然后尝试下面的步骤
2. 如何直接对根路径进行拦截
还是直接说流程吧:
必须在web.xml中加入如下:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
在web.xml中加入这段代码后发现并没有生效,不清楚原因,使用的是jetty7服务器,后来查了相关资料,发现有两种方式。
@RequestMapping("/")
public ModelAndView index() {
Map<String, Object> modelMap = new HashMap<String, Object>();
System.out.println("**********************");
/*
* modelMap.put("basPostTypeList",homeService.findBasPostTypeList());
* modelMap
* .put("busHotCompanyPostList",busHotCompanyPostService.getAllByOrderNum
* ());
*/
return new ModelAndView("index", modelMap);
}
或者,没有controller,只有view,也可以简化,在servlet的配置文件中加入:
<mvc:view-controller path="/" view-name="index"/>
如果同时都有。反正只会有一个起作用。一般是先扫描的起作用。谁会先扫描到,就是看和<mvc:annotation-driven />比较,谁在前面。
版权声明:本文为博主原创文章,未经博主允许不得转载。
spingmvc项目根路径访问不到的更多相关文章
- Springboot实体类转JSON报错Could not find acceptable representation & 设置访问项目根路径的默认欢迎页面
=================实体类转JSON报错的解决办法============= 之前在springmvc的时候也报过这个错,原因以及springmvc中解决办法参考:https://www ...
- java读取项目根路径下和任意磁盘位置下的properties文件
1.读取项目根路径下的properties文件比较简单也是比较常见的一种操作. 具体代码如下: package com.xuanen.util; import java.util.Properties ...
- js获取网站项目根路径
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...
- js获取项目根路径
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...
- 在HTML页面中获取当前项目根路径的方法
在HTML页面获取项目根路径的方法: function getRootPath(){ var curPageUrl = window.document.location.href; var rootP ...
- js获取当前项目根路径URL (转自CSDN 红领巾-sunlight)
/** * //获取当前项目根路径 * @return {TypeName} */ function getRootPath(){ //获取当前网址,如: http://localhost:8083/ ...
- JavaWeb 获取请求网络协议、IP、端口号、项目根路径
JavaWeb 获取请求网络协议.IP.端口号.项目根路径 CreateTime--2018年6月1日16点32分 Author:Marydon 1.需求 在项目中,需要使用Java向本程序发送r ...
- Java中获取项目根路径和类加载路径的7种方法
引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. ...
- html 获取项目根路径
html 获取项目根路径 function getContextPath(){ var pathName = document.location.pathname; //当前文件的绝度路径 var i ...
随机推荐
- Glide4 高效加载图片的配置【转】
原文: Glide4 高效加载图片的配置 https://www.jianshu.com/p/a079713f280f
- 吴裕雄 python 机器学习-DMT(2)
import matplotlib.pyplot as plt decisionNode = dict(boxstyle="sawtooth", fc="0.8" ...
- 吴裕雄 python oracle检索数据(2)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- 关于php laravel5.1框架出现路由找不到的情况
开启apache模块在apache配置文件LoadModule rewrite_module modules/mod_rewrite.so前面的#去掉然后修改 vim /etc/init.d/htt ...
- 寒假生活第一天——Github初体验
快开学了,今天体验了一下github这个对我来说很是神秘的东西 它的定义来源于百度百科,如有异议,那就有吧.//gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格 ...
- webstocket 聊天
/** * 初始化socket **/ function initSocket(index_host){//端口号 if( !window.WebSocket ){ console.log(" ...
- 一个查询指定错误记录数据表错误记录条数的shell脚本
#!/bin/bash #author:skycheng #parameters db_user=dbuser db_pass=dbpass db_host=xxx.xxx.xxx.xxx datab ...
- ftp删除目录和文件,目录下有文件删除提示【550 Remove directory operation failed.】
注意:目录下有文件,直接删除目录会失败,提示550 Remove directory operation failed. 必须先将目录下的文件都删除,才能删除目录 ftp命令行: ftp删除目 ...
- 【scrapy】关于爬取的内容是Unicode编码
自己练习爬取拉钩网信息的时候爬取的信息如下: {'jobClass': [u'\u9500\u552e\u52a9\u7406'], 'jobUrl': u'https://www.lagou.com ...
- OpenSessionInViewFilter 的配置及作用(原文地址: http://blog.csdn.net/sunsea08/article/details/4545186)
spring为我们解决hibernate的Session的关闭与开启问题. Hibernate 允许对关联对象.属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Sessio ...