jsp源码实例3(获取jsp各种参数)
导读:收集整理的这篇文章主要介绍了jsp源码实例3(获取jsp各种参数),觉得挺不错的,现在分享给大家,也给大家做个参考。 package coreservlets;import java.i...
收集整理的这篇文章主要介绍了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/.
* & copy; 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 NameTH> Value");
for(int i=0; ivariables.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);
}
}
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: jsp源码实例3(获取jsp各种参数)
本文地址: https://pptw.com/jishu/604464.html
