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

2016-01-29 12:05 3 1 收藏

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

【 tulaoshi.com - Java 】

  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 + "</H1n" +
"<TABLE BORDER=1 ALIGN="CENTER"n" +
"<TR BGCOLOR="#FFAD00"n" +
"<THCGI Variable Name<THValue");
for(int i=0; i<variables.length; i++) {
String varName = variables[0];
String varValue = variables[i][1];
if (varValue == null)
varValue = "<INot 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);
}

来源:https://www.tulaoshi.com/n/20160129/1484563.html

延伸阅读
标签: Java JAVA基础
二、启动任务 start.jsp是web.xml部署描述符中声明的欢迎页面,web.xml的内容是: <?xml version="1.0" encoding="GB2312"? <!DOCTYPE web-app     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"     "http://java.sun.com/dtd/web-app_2_3.dtd" <web-app &nbs...
标签: Java JAVA基础
声明 在JSP程序中声明合法的变量和方法 JSP 语法 <%! declaration; [ declaration; ]+ ... % 例子 <%! int i = 0; % <%! int a, b, c; % <%! Circle a = new Circle(2.0); % 描述 声明你将要在JSP程序中用到的变量和方法。你也必须这样做,不然会出错. 你可以一次性声明多个变量和方法,只要以";"结尾就行,当然这些声...
标签: Web开发
代码如下: ?xml version="1.0" encoding="UTF-8" ? !DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd" %@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"% %@ page import="java.net.*"% % String location = ""; String location...
标签: Web开发
经常看到jsp的初学者问tomcat下如何配置jsp、servlet和bean的问题,于是总结了一下如何tomcat下配置jsp、servlet和ben,希望对那些初学者有所帮助。 一、开发环境配置 第一步:下载j2sdk和tomcat:到sun官方站(http://java.sun.com/j2se/1.5.0/download.jsp)下载j2sdk,注意下载版本为Windows Offline Installation的S...
标签: Web开发
Java Server Page(JSP)作为建立动态网页的技术正在不断升温。JSP和ASP、PHP、工作机制不太一样。一般说来,JSP页面在执行时是编译式,而不是解释式的。首次调用JSP文件其实是执行一个编译为Servlet的过程。当浏览器向服务器请求这一个JSP文件的时候,服务器将检查自上次编译后JSP文件是否有改变,如果没有改变,就直接执行Servlet,而不...

经验教程

508

收藏

18
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部