private  ServletConfig config;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String value = config.getInitParameter("data");
OutputStream out = response.getOutputStream();
out.write(value.getBytes());
} @Override
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
String value = getServletConfig().getInitParameter("data");
OutputStream out = response.getOutputStream();
out.write(value.getBytes());
OutputStream out = response.getOutputStream();
Enumeration<String> e = this.getServletConfig().getInitParameterNames();
while (e.hasMoreElements()) { // 遍历所有
String name = (String) e.nextElement();
String value = this.getServletConfig().getInitParameter(name);
out.write((name + ':' + value + "\r\n").getBytes());
}

以上代码都可以从 web.xml 中读取配置,配置在如下节点中的 <init-param></init-param> 里:

 <servlet>
<servlet-name>ServletDemo5</servlet-name>
<servlet-class>cn.itcast.ServletDemo5</servlet-class>
<init-param>
<param-name>data</param-name>
<param-value>x1x2x3</param-value>
</init-param>
</servlet>

[Java.Web][Servlet]读取配置的更多相关文章

  1. Java Web Servlet知识点讲解(一)

    一.Web应用架构 如图所示: HTTP协议:一个简单的请求一响应协议,通常运行在TCP之上,它指定了客户端可能发送给服务器什么样的信息以及得到什么样的响应. JDBC:Java语言中用来规范客户端程 ...

  2. java web开发环境配置系列(二)安装tomcat

    在今天,读书有时是件“麻烦”事.它需要你付出时间,付出精力,还要付出一份心境.--仅以<java web开发环境配置系列>来祭奠那逝去的…… 1.下载tomcat压缩包,进入官网http: ...

  3. java web开发环境配置系列(一)安装JDK

    在今天,读书有时是件“麻烦”事.它需要你付出时间,付出精力,还要付出一份心境.--仅以<java web开发环境配置系列>来祭奠那逝去的…… 1.下载JDK文件(http://www.or ...

  4. java web 中 读取windows图标并显示

    java web中读取windows对应文件名的 系统图标 ....显示 1.获取系统图标工具类 package utils;  import java.awt.Graphics;  import j ...

  5. java web Servlet开发(二)

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  6. java web servlet

    一.什么是Servlet Servlet是一种小型的Java程序,它扩展了Web服务器的功能.作为一种服务器端的应用,他是运行在Servlet容器当中,例如Tomcat就是一种流行的Servlet容器 ...

  7. Java Web开发环境配置(JDK+Tomcat++IDEA 14)

    对于未接触过java web开发的大家而言,应该和我一样对java web编程开发比较迷茫,通过查一些资料,大致清楚了java web开发环境的一些基本配置,未做过相关编程的人员可以看一看,由于我刚接 ...

  8. 《转载》IntelliJ 2016.2 IDEA 中进行 Java Web 项目开发配置

    本文转载自 https://segmentfault.com/a/1190000007088964 1. 新建一个 Web Application 项目 打开 IntelliJ,选择新建项目: 左边栏 ...

  9. Java Web -- Servlet(1) 必备知识

    学习Java WEB开发必备的基本概念: 1.WEB 本意是蜘蛛网和网的意思.在网页设计中我们称为网页的意思. 现广泛译作网络.互联网等技术领域.表现为三种形式,即超文本(hypertext).超媒体 ...

随机推荐

  1. 网页宽高clientWidth clientHeight获得数值不对的问题

    当网页内容撑不满一屏时,通过以下代码获得整个网页高度会有问题 document.body.clientHeight;document.body.clientWidth; 得到的宽高不对,可能是因为ht ...

  2. C++11_ Variadic Templates

    版权声明:本文为博主原创文章,未经博主允许不得转载. 这次主要介绍C++11的又一个新特性 Variadic Templates (可变模板参数) 它的实现类似于initializer_list< ...

  3. L154

    Several possessions of the late physicist's Stephen Hawking will be included in an upcoming auction ...

  4. ffmpeg jpeg图片播放失败之问题排查

    播放jpeg时,avformat_find_stream_info出现以下问题,排查: [jpeg_pipe @ 0x146a80] Could not find codec parameters f ...

  5. device-independent bitmap (DIB) 设备无关位图

    设备无关位图即独立于设备的位图(DIB)与"Device-Dependent Bitmaps (DDB) 设备相关位图"相比,它不再依赖于具体的设备,从而更适合在不同的计算机之间传 ...

  6. hexo部署Github博客

    例子:https://aquarius1993.github.io/blog/ 仓库:https://github.com/Aquarius1993/blog (前提是已经安装Xcode和git) 1 ...

  7. Vue之通过代理设置跨域访问

    我们使用脚手架创建的项目,可以在config项目中看到

  8. apk系统签名命令

    java -jar signapk.jar platform.x509.pem platform.pk8 D:/ClockSetting.apk D:/ClockSettingSigned.apk 需 ...

  9. object references an unsaved transient instance - save the transient instance before flushing: com.jspxcms.core.domain.ScTeam

    object references an unsaved transient instance - save the transient instance before flushing: com.j ...

  10. Redis 字符串与哈希

    /*** * 字符串 redis里的字符串 ***/ //设置key的值 redis 127.0.0.1:6379> set key 'my name is imay' //设置值的过期时间 ( ...