PS:这两天在看java的东西,顺便总结两个JSP环境信息探针,做了一些修改。UTF-8编码,在linux下直接复制保存为xxx.jsp就可以,win中文版里面默认编码是gb码,建议用文本编辑器另存为UTF-8编码,否则可能显示乱码。
第一个如下:
<%@page contentType="text/html;charset=UTF-8"%>
<%@page import="java.io.*,java.util.*,java.net.*" %>
<%!
String tblWidth = "700";
String tblAlign = "center";
String strOS =System.getProperty("os.name");
private String getIp()
{
String strTmp="";
try
{
strTmp =InetAddress.getLocalHost().getHostAddress();
return strTmp;
}
catch(Exception e)
{
return strTmp;
}
}
private String getSystemEnv() throws Exception
{
String OS = System.getProperty("os.name").toLowerCase();
StringBuffer sb=new StringBuffer("");
Process p=null;
if(OS.indexOf("windows")>-1)
{
p=Runtime.getRuntime().exec("cmd /c set");
}
else
{
p=Runtime.getRuntime().exec("/bin/sh -c set");
}
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line=br.readLine())!=null)
{
sb.append(line+"<br>");
}
return sb.toString();
}
private String getDrivers()
{
StringBuffer sb=new StringBuffer("");
File roots[]=File.listRoots();
for(int i=0;i<roots.length;i++)
{
sb.append(roots[i]+" ");
}
return sb.toString();
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jsp探针</title>
<style type="text/css">
<!--
body,td,th {
font-size: 9pt;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.STYLE4 {color: #000000}
.STYLE5 {font-weight: bold; font-size: 10pt;}
.STYLE7 {font-size: 10}
-->
</style>
</head>
<body>
<table align="center" width="277" border="0">
<tr>
<td width="90" align="center">JSP探针 v1.1 </td>
<td width="85" align="center"><a href="http://www.macd11.com">服务器运维与架构</a></td>
</tr>
</table>
<div align="center"><br>
<table width="<%=tblWidth%>" align="<%=tblAlign%>" border="0" cellspacing="0" cellpadding="1">
<tr>
<td colspan="2" height="22" bgcolor="#E0E0E0"><span class="STYLE5">服务器基本信息
</span> </td>
</tr>
<tr>
<td height="23" width="20%" >服务器名称</td>
<td><%= request.getServerName() %> </td>
</tr>
<tr>
<td height="23" width="20%" >域名/IP </td>
<td><%= request.getServerName() %>
<%=getIp()%> </td>
</tr>
<tr>
<td height="23">服务器端口 </td>
<td><%= request.getServerPort() %> </td>
</tr>
<tr>
<td height="23">客户端端口 </td>
<td><%= request.getRemotePort() %> </td>
</tr>
<tr>
<td height="23">客户端IP </td>
<td><%= request.getRemoteAddr() %> </td>
</tr>
<tr>
<td height="23">Web 服务器 </td>
<td><%= application.getServerInfo() %> </td>
</tr>
<tr>
<td height="23">操作系统 </td>
<td><%= strOS+" "+System.getProperty("sun.os.patch.level")+" Ver:"+System.getProperty("os.version") %> </td>
</tr>
<tr>
<td height="23">服务器时间 </td>
<td><%=new Date().toLocaleString()%> </td>
</tr>
<tr>
<td height="23" width="20%" >CPU 信息 </td>
<td><%= System.getProperty("os.arch")%> </td>
</tr>
<tr>
<td height="23" width="20%" >磁盘分区 </td>
<td><%= getDrivers()%> </td>
</tr>
<tr>
<td height="23" width="20%" >用户当前工作目录 </td>
<td><%= System.getProperty("user.dir")%> </td>
</tr>
<tr>
<td height="23">本文件路径 </td>
<td><%= application.getRealPath(request.getRequestURI()) %> </td>
</tr>
</table>
<br>
<table width="<%=tblWidth%>" align="<%=tblAlign%>" border="0" cellspacing="0" cellpadding="1">
<tr>
<td colspan="2" height="22" bgcolor="#E0E0E0"><span class="STYLE4"><span class="STYLE5">Java 相关信息</span></span> </td>
</tr>
<tr>
<td height="23" width="20%" ><span class="STYLE7">JDK 版本</span> </td>
<td><%= System.getProperty("java.version") %> </td>
</tr>
<tr>
<td height="23" width="20%" >Servlet 版本 </td>
<td><%= application.getMajorVersion()+"."+application.getMinorVersion() %> </td>
</tr>
<tr>
<td height="23" width="20%" >JDK 安装路径 </td>
<td><%= System.getProperty("java.home")%> </td>
</tr>
<tr>
<td height="23" width="20%" >编码 </td>
<td><%= System.getProperty("file.encoding")%> </td>
</tr>
<tr>
<td height="23" width="20%" >JAVA类路径 </td>
<td><%= System.getProperty("java.class.path")%> </td>
</tr>
</table>
<br>
<table width="<%=tblWidth%>" align="<%=tblAlign%>" border="0" cellspacing="0" cellpadding="1">
<tr>
<td colspan="2" height="22" bgcolor="#E0E0E0">服务器环境变量 </td>
</tr>
<tr>
<td colspan="2"><%= getSystemEnv() %> </td>
</tr>
</table>
<br>
</div>
</body>
</html>
输出如图所示:
第二个如下:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@page import="java.util.*"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.awt.*"%>
<%@page import="java.io.*"%>
<%
/*
作者:淘特
*/
long startTime = System.currentTimeMillis();
long startMem = Runtime.getRuntime().freeMemory();
%>
<%!
public class LibInfo {
boolean supportJNDI = false;
boolean supportJavaxSql = false;
boolean supportJAF = false;
boolean supportMail = false;
boolean supportBeanUtils = false;
boolean supportCommonLogging = false;
boolean supportCommonCodec = false;
boolean supportCommonCollection = false;
boolean supportCommonDigester = false;
boolean supportCommonLang = false;
boolean supportJakartaRegExp = false;
boolean supportLucene = false;
boolean supportDom4j = false;
boolean supportMmMysqlDriver = false;
boolean supportComMysqlDriver = false;
boolean supportImageProcessing = false;
public LibInfo() {
try {
Class.forName("javax.naming.Name");
supportJNDI = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("javax.sql.DataSource");
supportJavaxSql = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("javax.activation.DataSource");
supportJAF = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("javax.mail.Message");
supportMail = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.commons.beanutils.MethodUtils");
supportBeanUtils = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.commons.logging.LogFactory");
supportCommonLogging = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.commons.codec.Decoder");
supportCommonCodec = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.commons.collections.ArrayStack");
supportCommonCollection = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.commons.digester.Digester");
supportCommonDigester = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.commons.lang.SystemUtils");
supportCommonLang = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.regexp.RE");
supportJakartaRegExp = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.apache.lucene.index.IndexWriter");
supportLucene = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.dom4j.Document");
supportDom4j = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("org.gjt.mm.mysql.Driver");
supportMmMysqlDriver = true;
} catch (ClassNotFoundException ex) {}
try {
Class.forName("com.mysql.jdbc.Driver");
supportComMysqlDriver = true;
} catch (ClassNotFoundException ex) {}
try {
BufferedImage bufferedImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufferedImage.createGraphics();
g.drawLine(0, 0, 10, 10);
g.dispose();// free resource
supportImageProcessing = true;
} catch (Throwable ex) {}
}
public boolean isSupportJAF() {
return supportJAF;
}
public boolean isSupportJavaxSql() {
return supportJavaxSql;
}
public boolean isSupportJNDI() {
return supportJNDI;
}
public boolean isSupportMail() {
return supportMail;
}
public boolean isSupportBeanUtils() {
return supportBeanUtils;
}
public boolean isSupportCommonLogging() {
return supportCommonLogging;
}
public boolean isSupportCommonCodec() {
return supportCommonCodec;
}
public boolean isSupportCommonCollection() {
return supportCommonCollection;
}
public boolean isSupportCommonDigester() {
return supportCommonDigester;
}
public boolean isSupportCommonLang() {
return supportCommonLang;
}
public boolean isSupportJakartaRegExp() {
return supportJakartaRegExp;
}
public boolean isSupportLucene() {
return supportLucene;
}
public boolean isSupportDom4j() {
return supportDom4j;
}
public boolean isSupportMmMysqlDriver() {
return supportMmMysqlDriver;
}
public boolean isSupportComMysqlDriver() {
return supportComMysqlDriver;
}
public boolean isSupportImageProcessing() {
return supportImageProcessing;
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JSP探针</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
.style1 {color: #FFFFFF; font-size:14px; font-weight:bold;}
.line20{line-height:20px;}
.table-header-text { color: #FFFFFF;
font-weight: normal;
margin: 3px 5px 1px 15px;
font-family: Arial, Verdana,Helvetica, Sans-Serif;
}
td{white-space:normal; word-break:break-all;}
-->
</style>
</head>
<body>
<table width="100%" height="25" border="0" cellpadding="0" cellspacing="0" bgcolor="#006000">
<tr>
<td><div align="center"><span class="style1">JSP探针</span></div></td>
</tr>
</table>
<h3>Request Variables:</h3>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
<tr>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getAuthType</td>
<td bgcolor="#FFFFFF"> <%=request.getAuthType()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getCharacterEncoding</td>
<td bgcolor="#FFFFFF"> <%=request.getCharacterEncoding()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getContentLength</td>
<td bgcolor="#FFFFFF"> <%=request.getContentLength()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getContentType</td>
<td bgcolor="#FFFFFF"> <%=request.getContentType()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getContextPath</td>
<td bgcolor="#FFFFFF"> <%=request.getContextPath()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getLocale</td>
<td bgcolor="#FFFFFF"> <%=request.getLocale()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getLocales</td>
<td bgcolor="#FFFFFF"> <%=request.getLocales()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getMethod</td>
<td bgcolor="#FFFFFF"> <%=request.getMethod()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getPathInfo</td>
<td bgcolor="#FFFFFF"> <%=request.getPathInfo()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getPathTranslated</td>
<td bgcolor="#FFFFFF"> <%=request.getPathTranslated()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getProtocol</td>
<td bgcolor="#FFFFFF"> <%=request.getProtocol()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getReader</td>
<td bgcolor="#FFFFFF"> <%=request.getReader()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRealPath</td>
<td bgcolor="#FFFFFF"> <%=request.getRealPath(".")%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRemoteAddr</td>
<td bgcolor="#FFFFFF"> <%=request.getRemoteAddr()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRemoteHost</td>
<td bgcolor="#FFFFFF"> <%=request.getRemoteHost()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRemoteUser</td>
<td bgcolor="#FFFFFF"> <%=request.getRemoteUser()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRequestDispatcher</td>
<td bgcolor="#FFFFFF"> <%=request.getRequestDispatcher("/")%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRequestURI</td>
<td bgcolor="#FFFFFF"> <%=request.getRequestURI()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getRequestURL</td>
<td bgcolor="#FFFFFF"> <%=request.getRequestURL()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getServerName</td>
<td bgcolor="#FFFFFF"> <%=request.getServerName()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getServerPort</td>
<td bgcolor="#FFFFFF"> <%=request.getServerPort()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getServletPath</td>
<td bgcolor="#FFFFFF"> <%=request.getServletPath()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> getUserPrincipal</td>
<td bgcolor="#FFFFFF"> <%=request.getUserPrincipal()%></td>
</tr>
</table>
<h3>Session Variables:</h3>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
<tr>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
</tr>
<%
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = (String)session.getAttribute(name);
%>
<tr>
<td bgcolor="#FFFFFF"> <%=name%></td>
<td bgcolor="#FFFFFF"> <%=value%></td>
</tr>
<%
}
%>
</table>
<h3>Application Variables:</h3>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
<tr>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
</tr>
<%
e = application.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
%>
<tr>
<td bgcolor="#FFFFFF"> <%=name%></td>
<td bgcolor="#FFFFFF"> <%=application.getAttribute(name)%></td>
</tr>
<%
}
%>
</table>
<h3>Cookies Variables:</h3>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
<tr>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
</tr>
<%
Cookie[] cos=request.getCookies();
if(cos!=null){
for(int i=0;i<cos.length;i++)
{
%>
<tr>
<td bgcolor="#FFFFFF"> <%=cos[i].getName()%></td>
<td bgcolor="#FFFFFF"> <%=cos[i].getValue()%></td>
</tr>
<%
}
}
%>
</table>
<h3>Server Variables:</h3>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000" class="line20">
<tr>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Property </span></td>
<td width="50%" height="22" bgcolor="#006000"><span class="table-header-text">Value</span></td>
</tr>
<%
Properties props=System.getProperties();
Iterator iter=props.keySet().iterator();
while(iter.hasNext())
{
String key=(String)iter.next();
%>
<tr>
<td bgcolor="#FFFFFF"> <%=key%></td>
<td bgcolor="#FFFFFF"> <%=props.get(key)%></td>
</tr>
<%
}
%>
</table>
<h3>Lib Info</h3>
<%
LibInfo lib=new LibInfo();
%>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#006000">
<tr>
<td height="25" bgcolor="#006000"><span class="table-header-text">Property </span></td>
<td bgcolor="#006000"><span class="table-header-text">Value</span></td>
</tr>
<tr>
<td width="476" bgcolor="#FFFFFF">supportJNDI</td>
<td width="484" bgcolor="#FFFFFF"> <%=lib.isSupportJNDI()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportJavaxSql</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportJavaxSql()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportJAF</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportJAF()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportMail</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportMail()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportBeanUtils</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportBeanUtils()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportCommonLogging</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportCommonLogging()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportCommonCodec</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportCommonCodec()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportCommonCollection</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportCommonCollection()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportCommonDigester</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportCommonDigester()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportCommonLang</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportCommonLang()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportJakartaRegExp</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportJakartaRegExp()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportLucene</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportLucene()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportDom4j</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportDom4j()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportMmMysqlDriver</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportMmMysqlDriver()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportComMysqlDriver</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportComMysqlDriver()%></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">supportImageProcessing</td>
<td bgcolor="#FFFFFF"> <%=lib.isSupportImageProcessing()%></td>
</tr>
</table>
<p><br>
</p>
</body>
</html>
<%
long endMem = Runtime.getRuntime().freeMemory();
long total= Runtime.getRuntime().maxMemory();
out.println("Total Memory:"+total);
out.println("Start Memory:"+startMem);
out.println("End Memory:"+endMem);
out.println("Use memory: "+ (startMem - endMem));
long endTime = System.currentTimeMillis();
out.println("Use Time: "+ (endTime-startTime));
%>
输出如图所示: