------------ContextServlet.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();
  ServletContext context = getServletConfig().getServletContext();
  //获得工程相关信息
  out.println("获得了工程的相对路径:"+context.getRealPath("/")+"<br>");
  out.println("获取了Tomcat的信息: "+context.getServerInfo()+"<br>");
  out.println("获取了JNDI:"+context.getResource("/")+"<br>");
  out.println("获取了源程序的相对路径:"+context.getResourcePaths("/")+"<br>");
  //getInitParameter方法
  String date = context.getInitParameter("date");
  String myclass = context.getInitParameter("class");
  out.println("date is -- "+date+"<br>");
  out.println("class is -- "+myclass+"<br>");
  //集合方法
  Enumeration e = context.getInitParameterNames();
  while(e.hasMoreElements()){
   String pName=(String) e.nextElement();
   String pValue=context.getInitParameter(pName);
   out.println("<br><b>"+pName+"</b>&nbsp;");
   out.println("----- "+pValue+"<br>");
  }
 }

-------------------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>test4-03</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>
  <context-param>
   <param-name>date</param-name>
   <param-value>200</param-value>
  </context-param>
  <context-param>
   <param-name>class</param-name>
   <param-value>102</param-value>
  </context-param>
  <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>ContextServlet</servlet-name>
   <servlet-class>com.ContextServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>ContextServlet</servlet-name>
   <url-pattern>/servlet/ContextServlet</url-pattern>
  </servlet-mapping>
</web-app>

最新文章

  1. oracle数据查询
  2. js闭包
  3. bzoj1412最小割
  4. mac端的优秀抓包工具——Charles使用
  5. 推荐25款实用的 HTML5 前端框架和开发工具【下篇】
  6. Mathematics:Raising Modulo Numbers(POJ 1995)
  7. PLSQL Developer的使用
  8. ASP.NET中POST数据并跳转页面
  9. android.view.WindowLeaked解决办法
  10. 阿里游戏大数据sesson2_RF&amp;amp;GBRT(上)
  11. ioc和aop
  12. Sass入门:第四章
  13. JVM-3.内存
  14. 如何卸载CentOS自带的apache
  15. 【Centos】系统服务自启动配置
  16. /etc/nginx/nginx.conf配置文件详解
  17. Linux系统命令行整理
  18. 分布式事物(同样适用于dubbo事务等分布式事务)
  19. 记一下vue.js事件的修饰等问题
  20. Linux上的文件查找工具之locate与find

热门文章

  1. [转] Asp.net Report Viewer 简单实例
  2. ti processor sdk linux am335x evm /bin/setup-package-install.sh hacking
  3. RTP/RTCP(一)-H264关于RTP协议的实现
  4. DirectX截图黑屏的解决办法
  5. Ejabberd源码解析前奏--概述
  6. IO负载高的来源定位
  7. 我们究竟什么时候可以使用Ehcache缓存
  8. 数据仓库之ETL漫谈
  9. 【LeetCode 208】Implement Trie (Prefix Tree)
  10. LeetCode题解——Longest Common Prefix