当前位置:网站首页>JSP config对象的简介说明
JSP config对象的简介说明
2022-07-31 08:23:00 【qq_25073223】
转自:
下文笔者将讲述JSP中config对象的简介说明,如下所示:
config对象: 指JSP的配置信息 它实际就是一个ServletConfig实例 我们可以在config对象上获取Servlet的初始化参数
例:
获取servlet实例的名称
<%@ page language="java" contentType="text/html; charset=gb2132" pageEncoding="ISO-8859-1"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> </head> <body> <!-- 直接输出config的getServletName的值 --> <%=config.getServletName()%> </body> </html> -----以上代码,将输出以下信息----- jsp
例:
使用getInitParameter获取name
<%@ page language="java" contentType="text/html; charset=gb2132" pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<!-- 输出该JSP中名为name的参数配置信息 -->
name配置参数的值:<%=config.getInitParameter("name")%><br/>
<!-- 输出该JSP中名为age的参数配置信息 -->
age配置参数的值:<%=config.getInitParameter("age")%>
</body>
</html>
//web.xml
<servlet>
<!--指定servlet的名字-->
<servlet-name>config</servlet-name>
<!--指定哪一个JSP页面配置成Servlet-->
<jsp-file>/configTest2.jsp</jsp-file>
<!--配置名为name的参数,值为yeeku-->
<init-param>
<param-name>name</param-name>
<param-value>yeeku</param-value>
</init-param>
<!--配置名为age的参数,值为30-->
<init-param>
<param-name>age</param-name>
<param-value>30</param-value>
</init-param>
</servlet>
<servlet-mapping>
<!--指定将config Servlet配置到/config路径-->
<servlet-name>config</servlet-name>
<url-pattern>/config</url-pattern>
</servlet-mapping>
-------运行以上代码,将输出servlet的配置信息---边栏推荐
- 循环结构--for循环
- [Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Part 1)--Component UI
- MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
- Vue项目通过node连接MySQL数据库并实现增删改查操作
- MySQL 排序
- jupyter notebook初使用
- 搭建frp进行内网穿透
- A, MySQL principle of master-slave replication
- 刷题《剑指Offer》day06
- A brief introduction to the SSM framework
猜你喜欢

使用MySQL如何查询一年中每月的记录数
![[Cloud native] Introduction and use of Feign of microservices](/img/39/05cf7673155954c90e75a8a2eecd96.jpg)
[Cloud native] Introduction and use of Feign of microservices

ONES 入选 CFS 财经峰会「2022数字化创新引领奖」

Small application project development, jingdong mall 】 【 uni - app custom search component (below) - search history

0730~Mysql optimization

【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议

Flutter Paystack 所有选项实现

服务器上解压文件时提示“gzip: stdin: not in gzip format,tar: Child returned status 1,tar: Error is not recovera“

SQL 嵌套 N 层太长太难写怎么办?

PowerCLi 一键批量部署OVA 到esxi 7
随机推荐
0730~Mysql优化
[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket
MySQL安装教程
【Unity】编辑器扩展-03-拓展Inspector视图
2022 Hangzhou Electric Cup Super League 3
SSM整合案例分析(详解)
Regarding "computing power", this article is worth reading
普通函数的参数校验
搭建frp进行内网穿透
skynet中一条消息从取出到处理完整流程(源码刨析)
[What is the role of auto_increment in MySQL?】
傅里叶变换,拉普拉斯变换学习记录
2019 NeurIPS | Graph Convolutional Policy Network for Goal-Directed Molecular Graph Generation
Flutter Paystack 所有选项实现
Hematemesis summarizes thirteen experiences to help you create more suitable MySQL indexes
XSS详解
SQL 嵌套 N 层太长太难写怎么办?
New in Visual Studio: Low Priority Builds
MySQL 数据库基础知识(系统化一篇入门)
数组every和some方法的区别?