分享一个JSP探针程序

今天为朋友们分享一个JSP的探针程序,属于菠菜园多年的收藏,虽然并非个人所做,但我觉得还是非常实用的,尤其是在判断环境的时候。

效果图:

jsp探针

源代码:

  1. <%@ page contentType="text/html; charset=UTF-8" %>
  2. <%@page import="java.util.*"%>
  3. <%@page import="java.awt.image.BufferedImage"%>
  4. <%@page import="java.awt.*"%>
  5. <%@page import="java.io.*"%>
  6. <%
  7. /*
  8. 作者:淘特
  9. */
  10. long startTime = System.currentTimeMillis();
  11. long startMem = Runtime.getRuntime().freeMemory();
  12. %>
  13. <%!
  14. public class LibInfo {
  15. boolean supportJNDI = false;
  16. boolean supportJavaxSql = false;
  17. boolean supportJAF = false;
  18. boolean supportMail = false;
  19. boolean supportBeanUtils = false;
  20. boolean supportCommonLogging = false;
  21. boolean supportCommonCodec = false;
  22. boolean supportCommonCollection = false;
  23. boolean supportCommonDigester = false;
  24. boolean supportCommonLang = false;
  25. boolean supportJakartaRegExp = false;
  26. boolean supportLucene = false;
  27. boolean supportDom4j = false;
  28. boolean supportMmMysqlDriver = false;
  29. boolean supportComMysqlDriver = false;
  30. boolean supportImageProcessing = false;
  31. public LibInfo() {
  32. try {
  33. Class.forName("javax.naming.Name");
  34. supportJNDI = true;
  35. catch (ClassNotFoundException ex) {}
  36. try {
  37. Class.forName("javax.sql.DataSource");
  38. supportJavaxSql = true;
  39. catch (ClassNotFoundException ex) {}
  40. try {
  41. Class.forName("javax.activation.DataSource");
  42. supportJAF = true;
  43. catch (ClassNotFoundException ex) {}
  44. try {
  45. Class.forName("javax.mail.Message");
  46. supportMail = true;
  47. catch (ClassNotFoundException ex) {}
  48. try {
  49. Class.forName("org.apache.commons.beanutils.MethodUtils");
  50. supportBeanUtils = true;
  51. catch (ClassNotFoundException ex) {}
  52. try {
  53. Class.forName("org.apache.commons.logging.LogFactory");
  54. supportCommonLogging = true;
  55. catch (ClassNotFoundException ex) {}
  56. try {
  57. Class.forName("org.apache.commons.codec.Decoder");
  58. supportCommonCodec = true;
  59. catch (ClassNotFoundException ex) {}
  60. try {
  61. Class.forName("org.apache.commons.collections.ArrayStack");
  62. supportCommonCollection = true;
  63. catch (ClassNotFoundException ex) {}
  64. try {
  65. Class.forName("org.apache.commons.digester.Digester");
  66. supportCommonDigester = true;
  67. catch (ClassNotFoundException ex) {}
  68. try {
  69. Class.forName("org.apache.commons.lang.SystemUtils");
  70. supportCommonLang = true;
  71. catch (ClassNotFoundException ex) {}
  72. try {
  73. Class.forName("org.apache.regexp.RE");
  74. supportJakartaRegExp = true;
  75. catch (ClassNotFoundException ex) {}
  76. try {
  77. Class.forName("org.apache.lucene.index.IndexWriter");
  78. supportLucene = true;
  79. catch (ClassNotFoundException ex) {}
  80. try {
  81. Class.forName("org.dom4j.Document");
  82. supportDom4j = true;
  83. catch (ClassNotFoundException ex) {}
  84. try {
  85. Class.forName("org.gjt.mm.mysql.Driver");
  86. supportMmMysqlDriver = true;
  87. catch (ClassNotFoundException ex) {}
  88. try {
  89. Class.forName("com.mysql.jdbc.Driver");
  90. supportComMysqlDriver = true;
  91. catch (ClassNotFoundException ex) {}
  92. try {
  93. BufferedImage bufferedImage = new BufferedImage(1010, BufferedImage.TYPE_INT_RGB);
  94. Graphics2D g = bufferedImage.createGraphics();
  95. g.drawLine(001010);
  96. g.dispose();// free resource
  97. supportImageProcessing = true;
  98. catch (Throwable ex) {}
  99. }
  100. public boolean isSupportJAF() {
  101. return supportJAF;
  102. }
  103. public boolean isSupportJavaxSql() {
  104. return supportJavaxSql;
  105. }
  106. public boolean isSupportJNDI() {
  107. return supportJNDI;
  108. }
  109. public boolean isSupportMail() {
  110. return supportMail;
  111. }
  112. public boolean isSupportBeanUtils() {
  113. return supportBeanUtils;
  114. }
  115. public boolean isSupportCommonLogging() {
  116. return supportCommonLogging;
  117. }
  118. public boolean isSupportCommonCodec() {
  119. return supportCommonCodec;
  120. }
  121. public boolean isSupportCommonCollection() {
  122. return supportCommonCollection;
  123. }
  124. public boolean isSupportCommonDigester() {
  125. return supportCommonDigester;
  126. }
  127. public boolean isSupportCommonLang() {
  128. return supportCommonLang;
  129. }
  130. public boolean isSupportJakartaRegExp() {
  131. return supportJakartaRegExp;
  132. }
  133. public boolean isSupportLucene() {
  134. return supportLucene;
  135. }
  136. public boolean isSupportDom4j() {
  137. return supportDom4j;
  138. }
  139. public boolean isSupportMmMysqlDriver() {
  140. return supportMmMysqlDriver;
  141. }
  142. public boolean isSupportComMysqlDriver() {
  143. return supportComMysqlDriver;
  144. }
  145. public boolean isSupportImageProcessing() {
  146. return supportImageProcessing;
  147. }
  148. }
  149. %>
  150. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  151. <html>
  152. <head>
  153. <title>JSP探针</title>
  154. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  155. <style type="text/css">
  156. <!--
  157. .style1 {color: #FFFFFF; font-size:14px; font-weight:bold;}
  158. .line20{line-height:20px;}
  159. .table-header-text { color: #FFFFFF;
  160. font-weight: normal;
  161. margin: 3px 5px 1px 15px;
  162. font-family: Arial, Verdana,Helvetica, Sans-Serif;
  163. }
  164. td{white-space:normal; word-break:break-all;}
  165. -->
  166. </style>
  167. </head>
  168. <body>
  169. <table width="100%" height="25" border="0" cellpadding="0" cellspacing="0" bgcolor="#006000">
  170. <tr>
  171. <td><div align="center"><span class="style1">JSP探针</span></div></td>
  172. </tr>
  173. </table>
  174. <h3>Request Variables:</h3>
  175. <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
  176. <tr>
  177. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
  178. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
  179. </tr>
  180. <tr>
  181. <td bgcolor="#FFFFFF">&nbsp;getAuthType</td>
  182. <td bgcolor="#FFFFFF">&nbsp;<%=request.getAuthType()%></td>
  183. </tr>
  184. <tr>
  185. <td bgcolor="#FFFFFF">&nbsp;getCharacterEncoding</td>
  186. <td bgcolor="#FFFFFF">&nbsp;<%=request.getCharacterEncoding()%></td>
  187. </tr>
  188. <tr>
  189. <td bgcolor="#FFFFFF">&nbsp;getContentLength</td>
  190. <td bgcolor="#FFFFFF">&nbsp;<%=request.getContentLength()%></td>
  191. </tr>
  192. <tr>
  193. <td bgcolor="#FFFFFF">&nbsp;getContentType</td>
  194. <td bgcolor="#FFFFFF">&nbsp;<%=request.getContentType()%></td>
  195. </tr>
  196. <tr>
  197. <td bgcolor="#FFFFFF">&nbsp;getContextPath</td>
  198. <td bgcolor="#FFFFFF">&nbsp;<%=request.getContextPath()%></td>
  199. </tr>
  200. <tr>
  201. <td bgcolor="#FFFFFF">&nbsp;getLocale</td>
  202. <td bgcolor="#FFFFFF">&nbsp;<%=request.getLocale()%></td>
  203. </tr>
  204. <tr>
  205. <td bgcolor="#FFFFFF">&nbsp;getLocales</td>
  206. <td bgcolor="#FFFFFF">&nbsp;<%=request.getLocales()%></td>
  207. </tr>
  208. <tr>
  209. <td bgcolor="#FFFFFF">&nbsp;getMethod</td>
  210. <td bgcolor="#FFFFFF">&nbsp;<%=request.getMethod()%></td>
  211. </tr>
  212. <tr>
  213. <td bgcolor="#FFFFFF">&nbsp;getPathInfo</td>
  214. <td bgcolor="#FFFFFF">&nbsp;<%=request.getPathInfo()%></td>
  215. </tr>
  216. <tr>
  217. <td bgcolor="#FFFFFF">&nbsp;getPathTranslated</td>
  218. <td bgcolor="#FFFFFF">&nbsp;<%=request.getPathTranslated()%></td>
  219. </tr>
  220. <tr>
  221. <td bgcolor="#FFFFFF">&nbsp;getProtocol</td>
  222. <td bgcolor="#FFFFFF">&nbsp;<%=request.getProtocol()%></td>
  223. </tr>
  224. <tr>
  225. <td bgcolor="#FFFFFF">&nbsp;getReader</td>
  226. <td bgcolor="#FFFFFF">&nbsp;<%=request.getReader()%></td>
  227. </tr>
  228. <tr>
  229. <td bgcolor="#FFFFFF">&nbsp;getRealPath</td>
  230. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRealPath(".")%></td>
  231. </tr>
  232. <tr>
  233. <td bgcolor="#FFFFFF">&nbsp;getRemoteAddr</td>
  234. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRemoteAddr()%></td>
  235. </tr>
  236. <tr>
  237. <td bgcolor="#FFFFFF">&nbsp;getRemoteHost</td>
  238. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRemoteHost()%></td>
  239. </tr>
  240. <tr>
  241. <td bgcolor="#FFFFFF">&nbsp;getRemoteUser</td>
  242. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRemoteUser()%></td>
  243. </tr>
  244. <tr>
  245. <td bgcolor="#FFFFFF">&nbsp;getRequestDispatcher</td>
  246. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRequestDispatcher("/")%></td>
  247. </tr>
  248. <tr>
  249. <td bgcolor="#FFFFFF">&nbsp;getRequestURI</td>
  250. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRequestURI()%></td>
  251. </tr>
  252. <tr>
  253. <td bgcolor="#FFFFFF">&nbsp;getRequestURL</td>
  254. <td bgcolor="#FFFFFF">&nbsp;<%=request.getRequestURL()%></td>
  255. </tr>
  256. <tr>
  257. <td bgcolor="#FFFFFF">&nbsp;getServerName</td>
  258. <td bgcolor="#FFFFFF">&nbsp;<%=request.getServerName()%></td>
  259. </tr>
  260. <tr>
  261. <td bgcolor="#FFFFFF">&nbsp;getServerPort</td>
  262. <td bgcolor="#FFFFFF">&nbsp;<%=request.getServerPort()%></td>
  263. </tr>
  264. <tr>
  265. <td bgcolor="#FFFFFF">&nbsp;getServletPath</td>
  266. <td bgcolor="#FFFFFF">&nbsp;<%=request.getServletPath()%></td>
  267. </tr>
  268. <tr>
  269. <td bgcolor="#FFFFFF">&nbsp;getUserPrincipal</td>
  270. <td bgcolor="#FFFFFF">&nbsp;<%=request.getUserPrincipal()%></td>
  271. </tr>
  272. </table>
  273. <h3>Session Variables:</h3>
  274. <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
  275. <tr>
  276. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
  277. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
  278. </tr>
  279. <%
  280. Enumeration e = session.getAttributeNames();
  281. while (e.hasMoreElements()) {
  282. String name = (String)e.nextElement();
  283. String value = (String)session.getAttribute(name);
  284. %>
  285. <tr>
  286. <td bgcolor="#FFFFFF">&nbsp;<%=name%></td>
  287. <td bgcolor="#FFFFFF">&nbsp;<%=value%></td>
  288. </tr>
  289. <%
  290. }
  291. %>
  292. </table>
  293. <h3>Application Variables:</h3>
  294. <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
  295. <tr>
  296. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
  297. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
  298. </tr>
  299. <%
  300. e = application.getAttributeNames();
  301. while (e.hasMoreElements()) {
  302. String name = (String)e.nextElement();
  303. %>
  304. <tr>
  305. <td bgcolor="#FFFFFF">&nbsp;<%=name%></td>
  306. <td bgcolor="#FFFFFF">&nbsp;<%=application.getAttribute(name)%></td>
  307. </tr>
  308. <%
  309. }
  310. %>
  311. </table>
  312. <h3>Cookies Variables:</h3>
  313. <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
  314. <tr>
  315. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
  316. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
  317. </tr>
  318. <%
  319. Cookie[] cos=request.getCookies();
  320. if(cos!=null){
  321. for(int i=0;i<cos.length;i++)
  322. {
  323. %>
  324. <tr>
  325. <td bgcolor="#FFFFFF">&nbsp;<%=cos[i].getName()%></td>
  326. <td bgcolor="#FFFFFF">&nbsp;<%=cos[i].getValue()%></td>
  327. </tr>
  328. <%
  329. }
  330. }
  331. %>
  332. </table>
  333. <h3>Server Variables:</h3>
  334. <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
  335. <tr>
  336. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
  337. <td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
  338. </tr>
  339. <%
  340. Properties props=System.getProperties();
  341. Iterator iter=props.keySet().iterator();
  342. while(iter.hasNext())
  343. {
  344. String key=(String)iter.next();
  345. %>
  346. <tr>
  347. <td bgcolor="#FFFFFF">&nbsp;<%=key%></td>
  348. <td bgcolor="#FFFFFF">&nbsp;<%=props.get(key)%></td>
  349. </tr>
  350. <%
  351. }
  352. %>
  353. </table>
  354. <h3>Lib Info</h3>
  355. <%
  356. LibInfo lib=new LibInfo();
  357. %>
  358. <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000">
  359. <tr>
  360. <td height="25" bgcolor="#006000"><span class="table-header-text">Property </span></td>
  361. <td bgcolor="#006000"><span class="table-header-text">Value</span></td>
  362. </tr>
  363. <tr>
  364. <td width="476" bgcolor="#FFFFFF">supportJNDI</td>
  365. <td width="484" bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportJNDI()%></td>
  366. </tr>
  367. <tr>
  368. <td bgcolor="#FFFFFF">supportJavaxSql</td>
  369. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportJavaxSql()%></td>
  370. </tr>
  371. <tr>
  372. <td bgcolor="#FFFFFF">supportJAF</td>
  373. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportJAF()%></td>
  374. </tr>
  375. <tr>
  376. <td bgcolor="#FFFFFF">supportMail</td>
  377. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportMail()%></td>
  378. </tr>
  379. <tr>
  380. <td bgcolor="#FFFFFF">supportBeanUtils</td>
  381. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportBeanUtils()%></td>
  382. </tr>
  383. <tr>
  384. <td bgcolor="#FFFFFF">supportCommonLogging</td>
  385. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportCommonLogging()%></td>
  386. </tr>
  387. <tr>
  388. <td bgcolor="#FFFFFF">supportCommonCodec</td>
  389. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportCommonCodec()%></td>
  390. </tr>
  391. <tr>
  392. <td bgcolor="#FFFFFF">supportCommonCollection</td>
  393. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportCommonCollection()%></td>
  394. </tr>
  395. <tr>
  396. <td bgcolor="#FFFFFF">supportCommonDigester</td>
  397. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportCommonDigester()%></td>
  398. </tr>
  399. <tr>
  400. <td bgcolor="#FFFFFF">supportCommonLang</td>
  401. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportCommonLang()%></td>
  402. </tr>
  403. <tr>
  404. <td bgcolor="#FFFFFF">supportJakartaRegExp</td>
  405. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportJakartaRegExp()%></td>
  406. </tr>
  407. <tr>
  408. <td bgcolor="#FFFFFF">supportLucene</td>
  409. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportLucene()%></td>
  410. </tr>
  411. <tr>
  412. <td bgcolor="#FFFFFF">supportDom4j</td>
  413. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportDom4j()%></td>
  414. </tr>
  415. <tr>
  416. <td bgcolor="#FFFFFF">supportMmMysqlDriver</td>
  417. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportMmMysqlDriver()%></td>
  418. </tr>
  419. <tr>
  420. <td bgcolor="#FFFFFF">supportComMysqlDriver</td>
  421. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportComMysqlDriver()%></td>
  422. </tr>
  423. <tr>
  424. <td bgcolor="#FFFFFF">supportImageProcessing</td>
  425. <td bgcolor="#FFFFFF">&nbsp;<%=lib.isSupportImageProcessing()%></td>
  426. </tr>
  427. </table>
  428. <p><br>
  429. </p>
  430. </body>
  431. </html>
  432. <%
  433. long endMem = Runtime.getRuntime().freeMemory();
  434. long total= Runtime.getRuntime().maxMemory();
  435. out.println("Total Memory:"+total);
  436. out.println("Start Memory:"+startMem);
  437. out.println("End Memory:"+endMem);
  438. out.println("Use memory: "+ (startMem - endMem));
  439. long endTime = System.currentTimeMillis();
  440. out.println("Use Time: "+ (endTime-startTime));
  441. %>
你想把广告放到这里吗?

发表评论

您必须 登录 才能发表留言!