---------------ConfigServlet.java-----------

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  request.setCharacterEncoding("GB2312");
  response.setContentType("text/html;charset=gb2312");
  PrintWriter out = response.getWriter();
  ServletConfig config = getServletConfig();
  //getInitParameter方法
  String username = config.getInitParameter("username");
  String password = config.getInitParameter("password");
  out.print("username--"+username);
  out.print("password--"+password);
  //集合方法
  Enumeration<?> e = config.getInitParameterNames();
  while(e.hasMoreElements()){
   String pusername=(String) e.nextElement();
   String ppassword = config.getInitParameter(pusername);
   out.print("<br/><b>"+pusername+"</b>&nbsp;;&nbsp;");
   out.print("------"+ppassword);
  }
  out.close();
 }

----------------------web.xml----------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>ServletConfig</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>ConfigServlet</servlet-name>
    <servlet-class>com.ConfigServlet</servlet-class>
    <init-param>
     <param-name>username</param-name>
     <param-value>jspuser</param-value>
    </init-param>
    <init-param>
     <param-name>password</param-name>
     <param-value>123456</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
   <servlet-name>ConfigServlet</servlet-name>
   <url-pattern>/servlet/ConfigServlet</url-pattern>
  </servlet-mapping>
</web-app>

ServletContext1的更多相关文章

  1. 重温Servlet学习笔记--servletContext对象

    一个项目中只有一个ServletContext对象,我们可以在多个servlet中获取这个唯一的对象,使用它可以给多个servlet传递数据,我们通常成servletContext为上下文对象.这个对 ...

  2. Atitit  发帖机实现(1)-----UsrQBm2008 页面上下文规范

    Atitit  发帖机实现(1)-----UsrQBm2008 页面上下文规范 1.1. 网站绝对路径,页面绝对路径1 1.2. Java的javax.servlet.ServletContext1 ...

  3. 小谈-—ServletConfig对象和servletContext对象

    一.servletContext概述 servletContext对象是Servlet三大域对象之一,每个Web应用程序都拥有一个ServletContext对象,该对象是Web应用程序的全局对象或者 ...

  4. Servlet、ServletConfig、ServletContext深入学习

    1.Servlet学习 1.Servlet生命周期 Servlet 加载—>实例化—>服务—>销毁. init(servletConfig):(经过自己的测试发现会先调用这个而不是i ...

  5. servlet(一):从Sevlet到HttpServlet

    Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. servlet ...

  6. JAVAWEB - Servlet原理及其使用>从零开始学JAVA系列

    目录 Servlet原理及其使用 什么是Servlet Servlet的使用 编写一个Servlet,使用继承HttpServlet的方式 配置web.xml 很简单的几个JSP文件 小提示,如果继承 ...

  7. ServletContext介绍和用法总结

    ServletContext介绍和用法总结 学习总结 一.ServletContext 介绍 1. 概念 2. 作用 3. 获取 3.1 在实现类中获取 3.2 在 Spring 容器中获取 二.Se ...

随机推荐

  1. laravel Authentication and Security

    Creating the user modelFirst of all, we need to define the model that is going to be used to represe ...

  2. 深入理解ob_flush和flush的区别

    ob_flush/flush在手册中的描述, 都是刷新输出缓冲区, 并且还需要配套使用, 所以会导致很多人迷惑… 其实, 他们俩的操作对象不同, 有些情况下, flush根本不做什么事情.. ob_* ...

  3. cadence allegro PCB中怎么使查找元件时屏幕不移动

    先按F4进入show element状态,你在找元件,屏幕就会移动到你找的元件上面去,并且将视图放大.

  4. uboot源码整体框架

    源码解压以后,我们可以看到以下的文件和文件夹:  cpu 与处理器相关的文件.每个子目录中都包括cpu.c和interrupt.c.start.S.u-boot.lds. cpu.c:初始化CPU.设 ...

  5. Linux内核3.0移植并基于Initramfs根文件系统启动

    Linux内核移植与启动 Target borad:FL2440 Bootloader:U-boot-2010.09 交叉编译器:buildroot-2012.08 1.linux内核基础知识 首先, ...

  6. 正确认识Android的内存管理机制,合理关闭进程 (一)

    随着大家收货后会有很多乐粉晒内存,为啦方便大家,在网上搜集了一些相关Andriod管理的相关机制合理管理内存,整理下发个贴. 首先要知道Android系统是基于Linux 2.6内核开发的开源操作系统 ...

  7. CodeForces Good Bye 2014 B. New Year Permutation

    可能是因为这次没有分Div.1和Div.2,所以感觉题的难度比较大. 题意: 给出一个1~n的排列和一个邻接矩阵A,Aij = 1表示可以交换排列的第i项和第j项,问经过若干次交换后,求能够得到最小字 ...

  8. iOS application: how to clear notifications?

    http://stackoverflow.com/questions/8682051/ios-application-how-to-clear-notifications up vote105down ...

  9. 【转】COCOS2D-X之不断变化的数字效果Demo

    我们在玩"天天爱消除"或"天天连萌"的时候,每玩一盘后会有一个游戏结果界面,上面有一个显示所得分数的效果.今天我们这个Demo就是要实现与之相近的效果. 一.我 ...

  10. Ext入门学习系列(三)复杂自定义窗体

    通过前2节的学习,基本掌握了Ext的语法和运行原理,可以作出一些简单的应用.本节我们一起来完成复杂点的对话框操作,因为在实际项目中经常要用到确认对话框等多种操作,然后根据客户的选择作出不同的响应. 一 ...