zoukankan      html  css  js  c++  java
  • 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>&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>

  • 相关阅读:
    native2ascii在线转换
    MyEclipse修改用户名和密码
    MyEclipse6.0安装SVN
    局域网远程关机
    使用 StackTrace 获得更多跟 Exception 有关的信息 http://blog.joycode.com/ghj/archive/2008/03/05/114925.aspx
    地图投影
    高斯-克吕格尔平面直角坐标系
    突破IIS的客户端连接限制(MtaEdt22.exe)
    生成SQL脚本含表数据
    服务跟踪查看器工具 (SvcTraceViewer.exe)WCF http://blogs.msdn.com/wcftoolsteamblogcn/
  • 原文地址:https://www.cnblogs.com/daimazhang/p/5364988.html
Copyright © 2011-2022 走看看