jsp源码实例3(获取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[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);
}
}

(0)

相关推荐

  • jsp源码实例3(获取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*

  • jsp源码实例2(获取表单参数)

    package coreservlets; import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.util.*; /** Shows all the parameters sent to the servlet via either* GET or POST. Specially marks parameters that have* no values or multiple values

  • jsp源码实例5(cookie)

    package coreservlets; import java.io.*;import javax.servlet.*;import javax.servlet.http.*; /** Sets six cookies: three that apply only to the current* session (regardless of how long that session lasts)* and three that persist for an hour (regardless

  • jsp源码实例4(搜索引擎)

    package coreservlets; import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*; public class SearchEngines extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletExcep

  • jsp源码实例1(输出)

    package coreservlets; import java.io.*;import javax.servlet.*;import javax.servlet.http.*; /** Simple servlet that generates HTML.* <P>* Taken from Core Servlets and JavaServer Pages* from Prentice Hall and Sun Microsystems Press,* http://www.corese

  • JSP多种web应用服务器导致JSP源码泄漏漏洞

    JSP多种web应用服务器导致JSP源码泄漏漏洞 作者:中联绿盟 汉化:不详 整理:JSPER 受影响的系统: BEA Systems Weblogic 4.5.1 - Microsoft Windows NT 4.0 BEA Systems Weblogic 4.0.4 - Microsoft Windows NT 4.0 BEA Systems Weblogic 3.1.8 - Microsoft Windows NT 4.0 IBM Websphere Application Server

  • Android开发获取手机内网IP地址与外网IP地址的详细方法与源码实例

    在进行Android应用开发过程中,有时候会遇到获取当前Android设备所使用的网络IP地址的场景,有时候需要本地的网络IP地址,即局域网地址,更多的时候是需要当前网络的真实的对外IP地址,即真实的网络地址,如大数据分析时往往需要Android设备上传本地的外网地址.本文对各种IP地址的获取进行了总结. 首先用大家比较熟悉的电脑端局域网地址和外网地址的获取方式对比一下:(1).电脑端局域网地址获取方式,可以通过在终端命令行输入ipconfig进行查看,如下图IPv地址标识的就是本机的局域网地址

  • 微信小程序 自动登陆PHP源码实例(源码下载)

    微信小程序 自动登陆PHP源码实例 app.js 初始化APP自动登陆 您也可以在任何地方进行用户登陆验证 用法:首先在js文件中定义 var app = getApp(); app.getUserDataToken(); App({ onLaunch: function () { /*初始化APP自动登陆 * 您也可以在任何地方进行用户登陆验证 *用法:首先在js文件中定义 var app = getApp(); app.getUserDataToken(); */ this.getUserD

  • java向文件中追加内容与读写文件内容源码实例代码

    java向文件中追加内容与读写文件内容源码实例代码 向文件尾加入内容有多种方法,常见的方法有两种: RandomAccessFile类可以实现随机访问文件的功能,可以以读写方式打开文件夹的输出流 public void seek(long pos)可以将读写指针移到文件尾,参数Pos表示从文件开头以字节为单位测量的偏移位置,在该位置文件指针. public void write(int pos)将数据写到读写指针后面,完成文件的追加.参数pos表示要写入的Byte 通过FileWrite打开文件

  • 深入解析Vue源码实例挂载与编译流程实现思路详解

    在正文开始之前,先了解vue基于源码构建的两个版本,一个是 runtime only ,另一个是 runtime加compiler 的版本,两个版本的主要区别在于后者的源码包括了一个编译器. 什么是编译器,百度百科上面的解释是 简单讲,编译器就是将"一种语言(通常为高级语言)"翻译为"另一种语言(通常为低级语言)"的程序.一个现代编译器的主要工作流程:源代码 (source code) → 预处理器 (preprocessor) → 编译器 (compiler) →

随机推荐