| 站点地图 | 联系我
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | 书签 | ASP.Net书签 | 上善若水 厚德载物
 现在位置 :: 主页 >> 资料中心 >> ROOT / CODE / B/S / JSP/Servlet /
 

获取jsp各种参数

来源(www.knowsky.com)

From: http://www.knowsky.com/2021.html

获取jsp各种参数

文章类别:JSP技巧 | 发表日期:2001-5-25 星期五 | 文章等级: ★★★★★

转自:动态网站制作指南 | www.knowsky.compackage 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[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); 
} 
} 
 


Link: http://www.asm32.net/article_details.aspx?id=1244


浏览次数 518 发布时间 2006/6/26 14:22:51 从属分类 JSP/Servlet 【评论】【 】【打印】【关闭
 
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | 书签 | ASP.Net书签 | 京ICP备09029108号-1