您的位置:首页网页设计JSP技巧 → 获取jsp各种参数

获取jsp各种参数

时间:2004/11/7 3:36: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[i][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排序集锦源码Spring技术内幕jsp运行时我们常遇到的几个问题?NteBeans下JSP连接MySQL示例

人气排行 Java语言中内存泄漏及如何检测问题详解JSP中errorPage设置方法在JSP页面中实现检索数据的分页显示JAVA实现屏幕抓图 远程桌面控制用JSP下载word文件(不会直接用IE打开)如何直接在浏览器内运行SQL命令无边框窗口代码详解Spring技术内幕