springMVC项目,设置根路径对应的页面

来源:互联网 发布:win7红警网络进不去 编辑:程序博客网 时间:2024/06/06 09:32

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>

默认访问根路径,会访问index.**的页面


2.方法一: SpringMVC 对根路径进行拦截


在web.xml中加入如下:

<welcome-file-list>    <welcome-file></welcome-file></welcome-file-list>

此时,web服务器就知道,根路径不要web服务器来处理,而是由程序自身来处理。这时,index.html也就不起作用了。


3.方法二:在index.**中进行跳转至 相应的过滤地址


例如:index.jsp中

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">  </head>    <body><jsp:forward page="login"></jsp:forward>  </body></html>

参考:http://iammr.7.blog.163.com/blog/static/49102699201222643458216/



0 0