获取jsp各种参数
程序员文章站
2024-02-25 09:24:04
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);
}
}
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);
}
}
上一篇: 最长回文串
下一篇: 用jsp编写文件上载
推荐阅读
-
获取jsp各种参数
-
C#获取存储过程返回值和输出参数值的方法
-
JSP获取spring 的容器ApplicationContext 博客分类: Java WebJava spring容器JSP获取beanJSP获取容器WebApplicationContextUtils
-
spring MVC 获取请求体 博客分类: spring MVC 请求参数请求要素request stringrequest bodyspringMVC获取请求体
-
ASP.net中获取客户端参数操作系统信息
-
springmvc之获取参数的方法(必看)
-
java 获取request中的请求参数代码详解
-
PHP通过微信跳转的Code参数获取用户的openid(关键代码)
-
PHP PDO 调用存储过程 返回多个集合 和 输出参数 怎么获取
-
springmvc之获取参数的方法(必看)