动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Asp → 阅读文章

 jsp源码实例3(获取jsp各种参数)

作者来源: 
阅读 数 554 人次 , 2006-3-29 4:22:00 


package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

/** creates a table showing the current value of each
* of the standard cgi variables.
* <p>
* taken from core servlets and javaserver pages
* from prentice hall and sun microsystems press,
* http://www.coreservlets.com/.
* &copy; 2000 marty hall; may be freely used or adapted.
*/

public class showcgivariables extends httpservlet {
public void doget(httpservletrequest request,
httpservletresponse response)
throws servletexception, ioexception {
response.setcontenttype("text/html");
printwriter out = response.getwriter();
string[][] variables =
{ { "auth_type", request.getauthtype() },
{ "content_length",
string.valueof(request.getcontentlength()) },
{ "content_type", request.getcontenttype() },
{ "document_root",
getservletcontext().getrealpath("/") },
{ "path_info", request.getpathinfo() },
{ "path_translated", request.getpathtranslated() },
{ "query_string", request.getquerystring() },
{ "remote_addr", request.getremoteaddr() },
{ "remote_host", request.getremotehost() },
{ "remote_user", request.getremoteuser() },
{ "request_method", request.getmethod() },
{ "script_name", request.getservletpath() },
{ "server_name", request.getservername() },
{ "server_port",
string.valueof(request.getserverport()) },
{ "server_protocol", request.getprotocol() },
{ "server_software",
getservletcontext().getserverinfo() }
};
string title = "servlet example: showing cgi variables";
out.println(servletutilities.headwithtitle(title) +
"<body bgcolor=\"#fdf5e6\">\n" +
"<h1 align=\"center\">" + title + "</h1>\n" +
"<table border=1 align=\"center\">\n" +
"<tr bgcolor=\"#ffad00\">\n" +
"<th>cgi variable name<th>value");
for(int i=0; i<variables.length; i++) {
string varname = variables[0];
string varvalue = variables[i][1];
if (varvalue == null)
varvalue = "<i>not specified</i>";
out.println("<tr><td>" + varname + "<td>" + varvalue);
}
out.println("</table></body></html>");
}

/** post and get requests handled identically. */

public void dopost(httpservletrequest request,
httpservletresponse response)
throws servletexception, ioexception {
doget(request, response);
}
}

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:jsp源码实例4(搜索引擎)
· 下一篇:jsp源码实例2(获取表单参数)
· IIS 5.0新功能
· VBScript 编码约定
· 新增一个Web页面
· Chinaasp论坛精华帖全文检索器技术内幕
· ASP小偷(远程数据获取)程序入门教程


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077