獲取jsp各種參數(shù)
更新時(shí)間:2006年10月13日 00:00:00 作者:
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 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 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);
}
}
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 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 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);
}
}
您可能感興趣的文章:
- jsp提交到Servlet報(bào)404錯(cuò)誤問題解決(webroot下子目錄)
- jsp include引用非本級(jí)目錄網(wǎng)頁實(shí)現(xiàn)代碼
- 兩個(gè)JSP頁面父頁面獲取子頁面內(nèi)容的兩種方法
- JSP 獲取Spring 注入對(duì)象示例
- jsp頁面獲取服務(wù)器時(shí)間的簡單調(diào)用示例
- jsp獲取action傳來的session和session清空以及判斷
- JSP自定義標(biāo)簽獲取用戶IP地址的方法
- jsp中獲取狀態(tài)怎么寫(兩種實(shí)現(xiàn)方式)
- JSP中獲取ExtJS.Ajax前臺(tái)傳遞的JSON數(shù)據(jù)實(shí)現(xiàn)過程
- JSP 獲取真實(shí)IP地址的代碼
- jsp中獲取當(dāng)前目錄的方法
相關(guān)文章
ssh生成隨機(jī)數(shù)字驗(yàn)證碼操作步驟
隨機(jī)數(shù)字驗(yàn)證碼生成方法很多,接下來將介紹下jsp中時(shí)如何實(shí)現(xiàn)的,感興趣的朋友可以參考下,希望本文對(duì)你有所幫助2013-02-02SpringMail使用過程中的報(bào)錯(cuò)解決辦法
這篇文章主要介紹了SpringMail使用過程中的報(bào)錯(cuò)解決辦法的相關(guān)資料,希望通過本文能幫助到大家,讓大家解決遇到這樣的問題,需要的朋友可以參考下2017-10-10Jsp+Servlet實(shí)現(xiàn)簡單登錄注冊(cè)查詢
這篇文章主要介紹了Jsp+Servlet實(shí)現(xiàn)簡單登錄注冊(cè)查詢,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09response.setHeader參數(shù)、用法的介紹
response.setHeader 是用來設(shè)置返回頁面的頭 meta 信息, 使用時(shí) response.setHeader( name, contect );2008-11-11jsp+servlet實(shí)現(xiàn)文件上傳與下載功能
這篇文章主要為大家詳細(xì)介紹了jsp+servlet實(shí)現(xiàn)文件上傳與下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12JavaBean實(shí)現(xiàn)多文件上傳的兩種方法
JavaBean實(shí)現(xiàn)多文件上傳的兩種方法...2006-10-10