ServletContext1
---------------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> ; ");
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的更多相关文章
- 重温Servlet学习笔记--servletContext对象
一个项目中只有一个ServletContext对象,我们可以在多个servlet中获取这个唯一的对象,使用它可以给多个servlet传递数据,我们通常成servletContext为上下文对象.这个对 ...
- Atitit 发帖机实现(1)-----UsrQBm2008 页面上下文规范
Atitit 发帖机实现(1)-----UsrQBm2008 页面上下文规范 1.1. 网站绝对路径,页面绝对路径1 1.2. Java的javax.servlet.ServletContext1 ...
- 小谈-—ServletConfig对象和servletContext对象
一.servletContext概述 servletContext对象是Servlet三大域对象之一,每个Web应用程序都拥有一个ServletContext对象,该对象是Web应用程序的全局对象或者 ...
- Servlet、ServletConfig、ServletContext深入学习
1.Servlet学习 1.Servlet生命周期 Servlet 加载—>实例化—>服务—>销毁. init(servletConfig):(经过自己的测试发现会先调用这个而不是i ...
- servlet(一):从Sevlet到HttpServlet
Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. servlet ...
- JAVAWEB - Servlet原理及其使用>从零开始学JAVA系列
目录 Servlet原理及其使用 什么是Servlet Servlet的使用 编写一个Servlet,使用继承HttpServlet的方式 配置web.xml 很简单的几个JSP文件 小提示,如果继承 ...
- ServletContext介绍和用法总结
ServletContext介绍和用法总结 学习总结 一.ServletContext 介绍 1. 概念 2. 作用 3. 获取 3.1 在实现类中获取 3.2 在 Spring 容器中获取 二.Se ...
随机推荐
- node.js模块之http模块
如果你想向远程服务器发起HTTP 连接,Node 也是很好的选择.Node 在许多情景下都很适合使用,如使用Web service,连接到文档数据库,或是抓取网页.你可以使用同样的http 模块来发起 ...
- Nandflash 驱动移植
前段时间,研究了一下4G的Nandflash驱动.手头上只有飞凌6410BSP自带的Nandflash驱动,该驱动不支持K9GAG08U0D(2G)和K9LBG08U0D(4G)的Nandflash. ...
- Target host is not specified错误
对于httpClient4.3访问指定页面,可以从下面的demo抽取方法使用. 注意:对于URL必须使用 http://开始,否则会有如下报错信息: 或者在设置cookie时带上domain: coo ...
- poj2352Stars
http://poj.org/problem?id=2352 二维逆序数 按一个数排序 转化为1维的 之前用树状数组写过 这次用线段树敲了下 #include <iostream> #in ...
- 两个STL网址 总结的很好 && c++堆的网址
http://www.cnblogs.com/bigcat814/ http://blog.sina.com.cn/s/blog_7065a9de010154ve.html 堆 http://www. ...
- NLog 传递参数
用NLog记文件日志,一般都用{$basedir}变量,把日志记在运行的目录或者它的子目录下,遇到要写在其他目录的下,看了下Nlog找到用环境变量传参数. .net 里写 Environment.Se ...
- poj1823,3667
又来练线段树了…… poj1823题意很简单(明显的数据结构题),区间修改和统计最长连续空区间: 有了poj3468的基础,区间修改不是什么问题了,重点是求最长连续空区间:(弱弱的我纠结了好久) 在每 ...
- PASCALmath库
noi上是让用,noip让用么?貌似不让— — 反正是好东西.在FP中,Math库为我们提供了丰富的数学函数.以下介绍在OI中可能会用到的Math库中一些函数.过程. 使用方法:在程序头用Uses语句 ...
- 高性能PHP支持静态类型
PHP+QB是一个可选的PHP虚拟机,它声称在性能上提供了数量级的提升.而负面影响就是它需要所有的内容都必须是静态类型,同时也对数组做了一些限制. 静态 类型声明 是通过PHPDoc语法的一个扩展添加 ...
- sockaddr和sockaddr_in的区别(转载)
原文链接:http://kenby.iteye.com/blog/1149001 struct sockaddr和struct sockaddr_in这两个结构体用来处理网络通信的地址. 在各种系统调 ...