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

时间: 2024-10-27 06:29:50

jsp源码实例3(获取jsp各种参数)_JSP编程的相关文章

Java源码分析:深入探讨Iterator模式_JSP编程

java.util包中包含了一系列重要的集合类.本文将从分析源码入手,深入研究一个集合类的内部结构,以及遍历集合的迭代模式的源码实现内幕. 下面我们先简单讨论一个根接口Collection,然后分析一个抽象类AbstractList和它的对应Iterator接口,并仔细研究迭代子模式的实现原理. 本文讨论的源代码版本是JDK 1.4.2,因为JDK 1.5在java.util中使用了很多泛型代码,为了简化问题,所以我们还是讨论1.4版本的代码. 集合类的根接口Collection Collect

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

js 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 multipl

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

js 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 JavaServe

jsp源码实例5(cookie)

cookie|js 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 ho

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

js|搜索引擎 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) throw

jsp源码实例1(输出)

js 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://w

jsp源码实例

js 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 Ser

jsp源码实例5(cookie)_JSP编程

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源码实例1(输出)_JSP编程

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