分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

jsp 项目中 web.xml 的作用

发布时间:2023-09-06 01:46责任编辑:彭小芳关键词:jsjspxml

每个 web 应用的 WEB-INF 路径下(而且必须位于该路径)的 web.xml 文件被称为配置描述符。

对于 java web 应用而言,WEB-INF 是一个特殊的文件夹,web 容器会包含该文件夹下的内容,客户浏览器无法访问 WEB-INF 路径下的任何内容。

在 servlet2.5 规范之前,java web 的绝大部分组件都通过 web.xml 文件来配置管理。

从 servlet3.0 开始,也可以通过注解来配置管理 web 组件,因此 web.xml 文件可以变得更加简洁。

web.xml 可以配置的内容:

1、配置 JSP

2、配置和管理 Servlet

3、配置和管理 Listener

4、配置和管理 Filter

5、配置标签库

6、配置 JSP 属性

除此之外,web.xml 还负责配置、管理如下常用内容。

1、配置和管理 JAAS 授权认证

2、配置和管理资源引用

3、web 应用首页

web.xml 文件的根元素是 <web-app .../> 元素,在 Servlet3.0 规范中,该元素新增了以下属性:

metadata-complete: 该属性接受 true 或 false 两个属性值。当为 true 的时候,该 web 应用将不会加载注解配置的 web 组件(如 Servlet、Filter、Listener 等)

配置首页的方法:

<welcome-file-list> ???<welcome-file>index.html</welcome-file> ???<welcome-file>index.htm</welcome-file> ???<welcome-file>index.jsp</welcome-file></welcome-file-list>

  

上面的配置指定该 web 应用首页依次是 index.html、index.htm、index.jsp。

如果 index.html 不存在,则由 index.htm 做首页,依次类推。

具体内容如下:

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" ?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ?xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee ?????????????????????http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" ?version="4.0" ?metadata-complete="true"><welcome-file-list> ?<welcome-file>index.html</welcome-file> ?<welcome-file>index.htm</welcome-file> ?<welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>

  

jsp 项目中 web.xml 的作用

原文地址:https://www.cnblogs.com/eleven24/p/8594524.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved