您的位置:首页网页设计JSP实例 → jsp源码实例3(获取jsp各种参数)

jsp源码实例3(获取jsp各种参数)

时间:2004/11/7 3:38:00来源:本站整理作者:蓝点我要评论(0)

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.

*



* 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) +

"\n" +

"

" + title + "

\n" +

"\n" +

"\n" +

"
CGI Variable NameValue");

for(int i=0; i
String varName = variables[0];

String varValue = variables[i][1];

if (varValue == null)

varValue = "Not specified";

out.println("
" + varName + "" + varValue);

}

out.println("
");

}



/** POST and GET requests handled identically. */



public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

doGet(request, response);

}

}

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 没有查询到任何记录。 学习java必学的几门技术jspSmartUpload上传下载全攻略Tomcat5.x中的虚拟主机配置方法利用iText在JSP中生成PDF报表

人气排行 告诉大家JSP连接数据库程序代码JSP单页面网站文件管理器jsp留言板源代码一: 给jsp初学者.在jsp中用bean和servlet联合实现用户注册、使用JSP + JAVABEAN + XML 开发的一个例子jsp在线考试系统-jsp文件 jsp计数器代码JSP/JAVABEAN+TOMCAT4.0.5+MYSQL组合建站总