当前位置:网站首页>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的配置信息---边栏推荐
猜你喜欢

MySQL安装常见报错处理大全

全国中职网络安全B模块之国赛题远程代码执行渗透测试 PHPstudy的后门漏洞分析
![mysql 数据去重的三种方式[实战]](/img/37/ad4007a32d9eb563a303756785e72f.png)
mysql 数据去重的三种方式[实战]

利用frp服务器进行内网穿透ssh访问

MySQL 5.7详细下载安装配置教程
![[Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Middle)--Search Suggestions](/img/ea/ee1ad50a497478b9d080bb5e4bdfb5.png)
[Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Middle)--Search Suggestions

MySQL安装教程

SQL语句知识大全

期刊会议排名、信息检索网站推荐以及IEEE Latex模板下载

ONES 入选 CFS 财经峰会「2022数字化创新引领奖」
随机推荐
二维坐标工具API
Which strings will be parsed as null by FastJson?
《如何戒掉坏习惯》读书笔记
模块化规范
[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
循环结构--for循环
The first part of the R language
SQL join table (inner join, left join, right join, cross join, full outer join)
XSS详解
Doraemon teach you forwarded and redirect page
【MySQL中auto_increment有什么作用?】
Kotlin 优点
【C#】说说 C# 9 新特性的实际运用
[转载] Virtual Studio 让系统找到需要的头文件和库
MySQL 5.7升级到8.0详细过程
【MySQL功法】第3话 · MySQL中常见的数据类型
0730~Mysql optimization
我的创作纪念日
TypeError The view function did not return a valid response. The function either returned None 的解决
【小程序项目开发-- 京东商城】uni-app之商品列表页面 (上)