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.
 1<p>   
 2* Taken from Core Servlets and JavaServer Pages   
 3* from Prentice Hall and Sun Microsystems Press,   
 4* http://www.coreservlets.com/.   
 5* © 2000 Marty Hall; may be freely used or adapted.   
 6*/   
 7  
 8public class ShowCGIVariables extends HttpServlet {   
 9public void doGet(HttpServletRequest request,   
10HttpServletResponse response)   
11throws ServletException, IOException {   
12response.setContentType("text/html");   
13PrintWriter out = response.getWriter();   
14String[][] variables =   
15{ { "AUTH_TYPE", request.getAuthType() },   
16{ "CONTENT_LENGTH",   
17String.valueOf(request.getContentLength()) },   
18{ "CONTENT_TYPE", request.getContentType() },   
19{ "DOCUMENT_ROOT",   
20getServletContext().getRealPath("/") },   
21{ "PATH_INFO", request.getPathInfo() },   
22{ "PATH_TRANSLATED", request.getPathTranslated() },   
23{ "QUERY_STRING", request.getQueryString() },   
24{ "REMOTE_ADDR", request.getRemoteAddr() },   
25{ "REMOTE_HOST", request.getRemoteHost() },   
26{ "REMOTE_USER", request.getRemoteUser() },   
27{ "REQUEST_METHOD", request.getMethod() },   
28{ "SCRIPT_NAME", request.getServletPath() },   
29{ "SERVER_NAME", request.getServerName() },   
30{ "SERVER_PORT",   
31String.valueOf(request.getServerPort()) },   
32{ "SERVER_PROTOCOL", request.getProtocol() },   
33{ "SERVER_SOFTWARE",   
34getServletContext().getServerInfo() }   
35};   
36String title = "Servlet Example: Showing CGI Variables";   
37out.println(ServletUtilities.headWithTitle(title) +   
38"<body bgcolor='\"#FDF5E6\"'>\n" +   
39"<h1 align='\"CENTER\"'>" + title + "</h1>\n" +   
40"<table align='\"CENTER\"' border="1">\n" +   
41"<tr bgcolor='\"#FFAD00\"'>\n" +   
42"<th>CGI Variable Name<th>Value");   
43for(int i=0; i<variables.length; (varvalue="null)" ;="" i++)="" if="" out.println("<tr="" string="" varname="variables[0];" varvalue="&lt;I&gt;Not specified&lt;/I&gt;" {=""><td>" + varName + "<td>" + varValue);   
44}   
45out.println("</td></td></variables.length;></th></th></tr></table></body>");   
46}   
47  
48/** POST and GET requests handled identically. */   
49  
50public void doPost(HttpServletRequest request,   
51HttpServletResponse response)   
52throws ServletException, IOException {   
53doGet(request, response);   
54}   
55}</p>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus