欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取jsp各种参数

程序员文章站 2023-12-17 16:12:58
package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.h...
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/.
* © 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[i][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);
}
}





上一篇:

下一篇: