1 5 package com.oreilly.servlet; 6 7 24 public class VersionDetector { 25 26 static String servletVersion; 27 static String javaVersion; 28 29 34 public static String getServletVersion() { 35 if (servletVersion != null) { 36 return servletVersion; 37 } 38 39 String ver = null; 49 try { 50 ver = "1.0"; 51 Class.forName("javax.servlet.http.HttpSession"); 52 ver = "2.0"; 53 Class.forName("javax.servlet.RequestDispatcher"); 54 ver = "2.1"; 55 Class.forName("javax.servlet.http.HttpServletResponse") 56 .getDeclaredField("SC_EXPECTATION_FAILED"); 57 ver = "2.2"; 58 Class.forName("javax.servlet.Filter"); 59 ver = "2.3"; 60 } 61 catch (Throwable t) { 62 } 63 64 servletVersion = ver; 65 return servletVersion; 66 } 67 68 73 public static String getJavaVersion() { 74 if (javaVersion != null) { 75 return javaVersion; 76 } 77 78 String ver = null; 85 try { 86 ver = "1.0"; 87 Class.forName("java.lang.Void"); 88 ver = "1.1"; 89 Class.forName("java.lang.ThreadLocal"); 90 ver = "1.2"; 91 Class.forName("java.lang.StrictMath"); 92 ver = "1.3"; 93 Class.forName("java.net.URI"); 94 ver = "1.4"; 95 } 96 catch (Throwable t) { 97 } 98 99 javaVersion = ver; 100 return javaVersion; 101 } 102 } 103 | Popular Tags |