获取jsp各种参数

2016-01-29 12:10 6 1 收藏

获取jsp各种参数,获取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[i][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);
}
}





 

来源:http://www.tulaoshi.com/n/20160129/1484923.html

延伸阅读
标签: Web开发
方法一: script type="text/javascript" !-- function Request(strName){   var strHref = "www.cnlei.org/index.htm?a=aaa&b=bbb&c=ccc";   var intPos = strHref.indexOf("?");   var strRight = strHref.substr(intPos + 1);  ...
标签: Web开发
最近做个页面,需要用javascript获取url参数,可发现网上的东西,实在是多了,错误也实在是多啊,真晕,浪费了我不少时间于是,我便总结一下,一个好用的就可以了,先声明下,用正则,是简单,但多浏览器的兼容性,和速度不敢保证了,所以我就用个多浏览器兼容的 代码如下: script language = javascript function reque...
标签: Web开发
最近网站改版,发现网站的广告都是直接网址,如果转向一下,对于本站的全职会好点 需要一个html页面来传递参数所以用到个js获取url参数的代码,就一个funciton 代码如下: script language="javascript" type="text/javascript" //js获取url参数的function function request(paras){  var u...
iphone沙箱模型有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library。 (NSHomeDirectory()), 手动保存的文件在documents文件里 Nsuserdefaults保存的文件在tmp文件夹里 1、Documents 目录 :您应该将所有de应用程序数据文件写入到这个目录下。这个目录用于存储...

经验教程

629

收藏

84

精华推荐

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