Get JSP various parameters _jsp programming

Source: Internet
Author: User
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 is 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 (title) + Servletutilities.headwithtitle
"<body bgcolor=\" #FDF5E6 \ ">\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[i][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);
}
}





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.