获取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);
}
}
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);
}
}
推荐阅读
-
超全的iOS各种设备信息获取方法总结(包括iPhone8/iPhone X)
-
解析web.xml中在Servlet中获取context-param和init-param内的参数
-
Servlet获取AJAX POST请求中参数以form data和request payload形式传输的方法
-
基于从request获取各种路径的方法介绍
-
vue如何获取自定义元素属性参数值的方法
-
C# 获取硬件参数的实现方法
-
springboot获取URL请求参数的多种方式
-
spring boot中controller的使用及url参数的获取方法
-
sqlserver获取各种形式的时间
-
C#分析URL参数并获取参数和值对应列表的方法