威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
JSP教程>> JSP基础教程 JSP高级教程 JSP常见问题
当前位置:首页 > JSP教程 > JSP常见问题
上一节 下一节
 获取jsp各种参数
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);
}
}






申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
JSP基础教程
JSP高级教程
JSP常见问题

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821