home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / APCHSSL2.ZIP / OS2HTTPD / servlets / _gsp / ___env.java < prev    next >
Encoding:
Java Source  |  1999-08-26  |  5.9 KB  |  113 lines

  1. package _gsp;
  2. import com.bitmechanic.gsp.*;
  3. import javax.servlet.http.*;
  4. import java.util.Enumeration; //l:\os2httpd\public\htdocs\gsp\env.gsp:1
  5. import java.util.Hashtable; //l:\os2httpd\public\htdocs\gsp\env.gsp:2
  6.  
  7.  
  8. public class ___env implements Template {
  9.   private static String __strArr[] = {
  10.     "\n",
  11.     "\n<html>\n<head>\n<title>EnvDumpServlet</title>\n</head>\n<body bgcolor=\"#ffffff\">\n<h3>EnvDumpServlet</h3>\n<h4>Headers available via HttpServletRequest.getHeader() </h4>\n<table border=\"1\">\n\n",
  12.     "\n\n</table><P>\n<h4>Attributes available via HttpServletRequest.getAttribute()</h4>\n<table border=\"1\">\n\n",
  13.     "\n\n</table><P>\n<h4>Form Elements available from HttpUtils.parsePostData()</h4>\n<table border=\"1\">\n\n",
  14.     "\n\n</table><P>\n</body>\n</html>\n",
  15.   };
  16.     private static char[][] __byteArr;
  17.     static {
  18.       __byteArr = new char[__strArr.length][];
  19.       for(int i = 0; i < __strArr.length; i++) {
  20.         __byteArr[i] = __strArr[i].toCharArray();
  21.       }
  22.       __strArr = null;
  23.     }
  24.     //note current time for comparisons latter
  25.     private static long __parseTime = Long.parseLong("935712254292");
  26.     private static com.bitmechanic.gsp.FileDependancy __dependancies[] = {  
  27.         new com.bitmechanic.gsp.FileDependancy ("l:\\os2httpd\\public\\htdocs\\gsp\\env.gsp","917922188000")};
  28.     public boolean usesPrintWriter() {
  29.         return true;
  30.     }
  31.     public boolean shouldCache() {
  32.         boolean __shouldCache = true;
  33.         for (int i = 0; i < __dependancies.length && __shouldCache; i++) {
  34.             if (!__dependancies[i].isCurrent())
  35.                 __shouldCache = false;
  36.         }
  37.         return __shouldCache;
  38.     }
  39.  
  40.     public long getParseTime() { return this.__parseTime; }
  41.     private java.util.Hashtable __cacheHash = new java.util.Hashtable();
  42.     public synchronized void flushExpiredCacheData() {
  43.       if(__cacheHash != null) {
  44.         long now = System.currentTimeMillis();
  45.         for(java.util.Enumeration e = __cacheHash.keys(); e.hasMoreElements();) {
  46.             Object key = e.nextElement();
  47.             CachedString cs = (CachedString)__cacheHash.get(key);
  48.             if(cs.hasExpired(now)) __cacheHash.remove(key);
  49.         }
  50.       }
  51.     }
  52.     public synchronized void flushAllCacheData() {
  53.       if(__cacheHash != null) {
  54.         __cacheHash.clear();
  55.       }
  56.     }
  57.  
  58.  
  59.     public ___env () {}
  60.  
  61.     public void render(Application application, GspRequest request, GspResponse response) throws Exception {
  62.         java.io.PrintWriter out = response.getWriter();
  63.     out.write(__byteArr[0]);
  64.     out.write(__byteArr[1]);
  65.  //l:\os2httpd\public\htdocs\gsp\env.gsp:12
  66.     // print headers //l:\os2httpd\public\htdocs\gsp\env.gsp:13
  67.     Enumeration headers = request.getHeaderNames(); //l:\os2httpd\public\htdocs\gsp\env.gsp:14
  68.     while ( headers.hasMoreElements()) { //l:\os2httpd\public\htdocs\gsp\env.gsp:15
  69.         String hdr = headers.nextElement().toString(); //l:\os2httpd\public\htdocs\gsp\env.gsp:16
  70.         out.println("<TR><TD><B>"+hdr + "</B></TD><TD>"+request.getHeader(hdr)+"</TD></TR>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:17
  71.     } //l:\os2httpd\public\htdocs\gsp\env.gsp:18
  72.     out.println("<TR><TD><B>accept</B></TD><TD>image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*</TD></TR>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:19
  73.  //l:\os2httpd\public\htdocs\gsp\env.gsp:20
  74.     out.write(__byteArr[2]);
  75.  //l:\os2httpd\public\htdocs\gsp\env.gsp:26
  76.     // print attributes //l:\os2httpd\public\htdocs\gsp\env.gsp:27
  77.     String prefix = "org.apache.jserv."; //l:\os2httpd\public\htdocs\gsp\env.gsp:28
  78.     Object attrsObj = request.getAttribute("org.apache.jserv.attribute_names"); //l:\os2httpd\public\htdocs\gsp\env.gsp:29
  79.     if ( attrsObj != null && attrsObj instanceof Enumeration ) { //l:\os2httpd\public\htdocs\gsp\env.gsp:30
  80.         Enumeration attrs = (Enumeration) attrsObj; //l:\os2httpd\public\htdocs\gsp\env.gsp:31
  81.         while ( attrs.hasMoreElements()) { //l:\os2httpd\public\htdocs\gsp\env.gsp:32
  82.             String attr = attrs.nextElement().toString(); //l:\os2httpd\public\htdocs\gsp\env.gsp:33
  83.             if ( request.getAttribute(prefix + attr) != null ) { //l:\os2httpd\public\htdocs\gsp\env.gsp:34
  84.             out.println("<TR><TD><B>"+prefix + attr + "</B></TD><TD>"+request.getAttribute(prefix + attr).toString()+"</TD></TR>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:35
  85.         } else { //l:\os2httpd\public\htdocs\gsp\env.gsp:36
  86.             out.println("<TR><TD><B>"+prefix + attr + "</B></TD><TD></TD></TR>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:37
  87.             } //l:\os2httpd\public\htdocs\gsp\env.gsp:38
  88.         } //l:\os2httpd\public\htdocs\gsp\env.gsp:39
  89.     } //l:\os2httpd\public\htdocs\gsp\env.gsp:40
  90.  //l:\os2httpd\public\htdocs\gsp\env.gsp:41
  91.     out.write(__byteArr[3]);
  92.  //l:\os2httpd\public\htdocs\gsp\env.gsp:47
  93.     // Look for POST data //l:\os2httpd\public\htdocs\gsp\env.gsp:48
  94.     String post = request.getMethod(); //l:\os2httpd\public\htdocs\gsp\env.gsp:49
  95.     if(post.equals("POST")) { //l:\os2httpd\public\htdocs\gsp\env.gsp:50
  96.         Hashtable nvPairs = HttpUtils.parsePostData(request.getIntHeader("content-length"), request.getInputStream()); //l:\os2httpd\public\htdocs\gsp\env.gsp:51
  97.         Enumeration keys = nvPairs.keys(); //l:\os2httpd\public\htdocs\gsp\env.gsp:52
  98.         while (keys.hasMoreElements()) { //l:\os2httpd\public\htdocs\gsp\env.gsp:53
  99.             String key = (String) keys.nextElement(); //l:\os2httpd\public\htdocs\gsp\env.gsp:54
  100.             out.print("<TR><TD><B>"+key+"</B></TD><TD>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:55
  101.             String[] values = (String[]) nvPairs.get(key); //l:\os2httpd\public\htdocs\gsp\env.gsp:56
  102.         for(int i=0; i<values.length; i++) { //l:\os2httpd\public\htdocs\gsp\env.gsp:57
  103.             out.print(""+values[i]+"<BR>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:58
  104.             } //l:\os2httpd\public\htdocs\gsp\env.gsp:59
  105.         out.print("</TD></TR>"); //l:\os2httpd\public\htdocs\gsp\env.gsp:60
  106.         } //l:\os2httpd\public\htdocs\gsp\env.gsp:61
  107.     } //l:\os2httpd\public\htdocs\gsp\env.gsp:62
  108.  //l:\os2httpd\public\htdocs\gsp\env.gsp:63
  109.     out.write(__byteArr[4]);
  110.         out.flush();
  111.     }
  112. }
  113.