中华技术网Servlet篇1-显示Servlet系统属性

Wuxuehui 2000-11-14 11:35:00
中华技术网Servlet篇1-显示Servlet系统属性 ( 连载篇 )
作者:Wuxuehui
网站:中华技术网 http://www.netqu.com

文件名:Servlet_Properties.java
-----------------------------------------
import javax.servlet.http.*;
import javax.servlet.*;

/* *
* 这是一个显示Servlet 服务器系统属性的列表程序
* This is a simple servlet that echo information
* about the client and also provide a listing of
* all of the system properties on the server.
*/
public class Servlet_Properties extends HttpServlet {
/* *
* 执行 HTTP GET 操做 ( Performs the HTTP GET operation )
* 参数 req 是客户端的要求值 ( Parameter req The request from the client )
* 参数 res 是服务器Servlet端的响应值 ( Parameter res The response from the servlet )
*/
public void doGet(
HttpServletRequest req,
HttpServletResponse res )
throws ServletException,java.io.IOException
{
// 设置 Servlet端的响应值内容类型 加入 'charset=gb2312' 这样 Servlet 才可以输出中文
// Set the content type of the response ,add 'charset=gb2312' support Chinese output
res.setContentType("text/html;charset=gb2312");
// 通过 PrintWriter 建立写权限输出Servlet端的响应值
// Create a PrintWriter to write the response
java.io.PrintWriter out = new java.io.PrintWriter(res.getOutputStream());
// 输出 HTML ( print the HTML )
out.println("<html><head><title>Java Servlet Properties</title><style>body,td {font-size:9pt;}</style></head><body bgcolor=white>");
out.println("<h3 align=center>Information About You</h3>");
out.println("
<center><table border=1 bordercolordark=white bordercolorlight=black cellpadding=0 cellspacing=0>");
out.println("<tr><td bgcolor=eeeeee>Method</td><td>" + req.getMethod() + "</td>");
out.println("<tr><td bgcolor=eeeeee>User</td><td>" + req.getRemoteUser() + "</td>");
out.println("<tr><td bgcolor=eeeeee>Client</td><td>" + req.getRemoteHost() + "</td>");
out.println("<tr><td bgcolor=eeeeee>Protocol</td><td>" + req.getProtocol() + "</td>");
out.println("</tr>");

java.util.Enumeration enum = req.getParameterNames();
// 显示URL参数值,可用 http://www.netqu.com/servlet/Properties?name=test 测试
// show URL Parameter browse http://www.netqu.com/servlet/Properties?name=test to test
while (enum.hasMoreElements()) {
String name = (String)enum.nextElement();
out.println("<tr>");
out.println("<td>Parameter'" + name + "'</td><td>" + req.getParameter(name) + "</td>");
out.println("</tr>");
}

out.println("</table>");
out.println("
<hr>
");
out.println("<h3 align=center>Server Properties</h3>");
out.println("
");
out.println("<table border=1 bordercolordark=white bordercolorlight=black cellpadding=0 cellspacing=0>");

java.util.Properties props = System.getProperties();
enum = props.propertyNames();

while (enum.hasMoreElements()) {
String name = (String)enum.nextElement();
out.println("<tr>");
out.println("<td bgcolor=eeeeee> " + name + "</td><td> " + props.getProperty(name) + "</td>");
out.println("</tr>");
}

out.println("</table><p><a href=http://www.netqu.com><img src=http://www.netqu.com/images/technet_banner.gif width=468 height=60 border=0 alt=中华技术网></a>

<a href=http://www.netqu.com/netqu_services.html target=_blank><font color=red>商业服务</font></a> | <a href=mailto:wuxuehui@sina.com?subject=站务合作>站务合作</a> | <a href=mailto:wuxuehui@sina.com?subject=广告联系>广告联系</a> | <a href=mailto:wuxuehui@sina.com?subject=联系方式>联系方式</a>
<table bgcolor=white><td>CopyRight © <a href=http://www.netqu.com>China Tech Net</a> All Rights Reserved Webmaster: <a href=mailto:Wuxuehui@sina.com?subject=fromnetqu>Wuxuehui</a> OICQ:178927 <img src=http://infocenter.tencent.com/178927/s/00/159/ width=16 height=16> ICQ: <a href=http://wwp.icq.com/2759606 target=_blank>2759606</a> <img width=55 height=14 src=http://online.mirabilis.com/scripts/online.dll?icq=2759606&img=9></table></p></center>");
// warp up
out.println("</body></html>");
out.flush();

}
/* *
* 初始化 Servlet. 叫做一次性Servlet载入.它可以保证编译前任何要求(request)值编译进servlet.
* Initialize the servlet. This is called once when the
* servlet is loaded. It is guaranteed to complete before any
* requests are made to the servlet
* 参数 cfg 设置 Servlet的信息
* Parameter cfg Servlet configuration information
*
*/
public void init(ServletConfig cfg)
throws ServletException
{
super.init(cfg);
}
/* *
* 摧毁 Servlet.卸载载入的Servlet程序
* Destroy the Servlet. This is called once when the servlet is unloaded.
*/

public void destroy()
{
super.destroy();
}
}
...全文
171 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧