JSP config对象
11个月前 (04-28)
JSP config 是 javax.servlet.ServletConfig 的实例对象,一般用于获取页面和 Servlet 的初始化参数。
config 对象的常用方法如下:
config 对象的常用方法如下:
方法 | 说明 |
---|---|
String getInitParameter(String paramname) | 获取指定的初始化参数值 |
Enumeration getInitParameterNames() | 获取当前页面所有的初始化参数值 |
ServletContext getServletContext() | 获取当前执行 Servlet 的 servletContext(Servlet 上下文)的值 |
String getServletName() | 获取当前执行 Servlet 的名称 |
示例
在 web.xml 文件中定义 Servlet 名称和映射,然后使用 config 对象获取信息。web.xml 代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.su网站站点" rel="nofollow" />
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>编程帮(www.biancheng网站站点" rel="nofollow" />
注意:因为 JSP 页面的实质是 Servlet,所以一般很少在 JSP 页面中使用 config 对象。