【Servlet】web.xml中welcome-file-list的作用

今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用:

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

启动服务器后,直接输入http://localhost:8080/project 终是报404错误,初步猜测是由于没有找到index.jsp这个文件造成的,于是在web-root下新建一个空白的index.jsp;重新启动之后成功显示,但是由于welcome-file中不能直接写action,所以对index.jsp进行改造:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:forward page="/index.html" />


这样就达到了只输入项目名就可访问的目的: 直接输入 http://localhost:8080/ project 

原文连接:web.xml中的welcome-file-list不起作用

原文地址:https://www.cnblogs.com/HDK2016/p/6219294.html