requset对象方法和实例

jsp request对象详解 带实例

public java.lang.Object getAttribute()
返回name制定的属性值,若name不存在返回null
public java.util.Enumeration getAttributeNames()
返回request对象所有属性的名字集合
public void setAttribute(String name,Object value)
返回该请求中的一个属性(属性的名字,属性的取值)

能够取得参数的方法
String getParameter(String name)   取得name的参数值
Enumeration getParameterNames()    取得所有的参数名字
String[] getParameterValues(*STring name) 取得所有name的参数值
Map getParameterMap()     取得一个要求参数的map

能够取得请求http标头的方法
String getHeader(String name)    取得name的标头
Enumeration getHeaderNames()    取得所有的标头名称
Enumeration getHeaders(String name)   取得所有name的标头
int getIntHeader(String name)    取得整数类型name的标头
long getDateHeader(String name)    取得日期类型的name的标头
Cookie[] getCookies()     取得与请求有关的cookies

其他方法
String getContextPath()     取得Context路径(即后台名称)
String getMethod()     取得http的方法
String getProtocol()     取得使用的协议
String getQueryString()     取得请求的参数字符串必须为(get)
String getRequestedSessionId()    取得客户端SessionID
String getRequestURI()     取得请求URL,不包括请求参数字符串
String getRemoteAddr()     取得用户ip地址
String getRemoteHost()     取得用户主机名称   
int getRemotePort()     取得用户主机端口   
String getRemoteUser()     取得用户名称   
void etCharacterEncoding(String encoding) 设定编码格式,用来解决窗体传递中文的问题

<%
out.println("Protocol: " + request.getProtocol() + "<br>");
out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo() + "<br>");
out.println("Remote Addr: " + request.getRemoteAddr() + "<br>");
out.println("Remote Host: " + request.getRemoteHost() + "<br>");
out.println("Character Encoding: " + request.getCharacterEncoding() + "<br>");
out.println("Content Length: " + request.getContentLength() + "<br>");
out.println("Content Type: "+ request.getContentType() + "<br>");
out.println("Auth Type: " + request.getAuthType() + "<br>");
out.println("HTTP Method: " + request.getMethod() + "<br>");
out.println("Path Info: " + request.getPathInfo() + "<br>");
out.println("Path Trans: " + request.getPathTranslated() + "<br>");
out.println("Query String: " + request.getQueryString() + "<br>");
out.println("Remote User: " + request.getRemoteUser() + "<br>");
out.println("Session Id: " + request.getRequestedSessionId() + "<br>");
out.println("Request URI: " + request.getRequestURI() + "<br>");
out.println("Servlet Path: " + request.getServletPath() + "<br>");
out.println("Accept: " + request.getHeader("Accept") + "<br>");
out.println("Host: " + request.getHeader("Host") + "<br>");      
out.println("Referer : " + request.getHeader("Referer") + "<br>");      
out.println("Accept-Language : " + request.getHeader("Accept-Language") + "<br>");      
out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding") + "<br>");      
out.println("User-Agent : " + request.getHeader("User-Agent") + "<br>");      
out.println("Connection : " + request.getHeader("Connection") + "<br>");      
out.println("Cookie : " + request.getHeader("Cookie") + "<br>");      
out.println("Created : " + session.getCreationTime() + "<br>");      
out.println("LastAccessed : " + session.getLastAccessedTime() + "<br>");      
out.println("Scheme: " + request.getScheme() + "<br>");
out.println("Server Name: " + request.getServerName() + "<br>" );
out.println("Server Port: " + request.getServerPort() + "<br>");
out.println("Protocol: " + request.getProtocol() + "<br>");
        
%>

运行结果:

Protocol: HTTP/1.1
Server Info: JavaServer Web Dev Kit/1.0 EA (JSP 1.0; Servlet 2.1; Java 1.2; Windows NT 5.0 x86; java.vendor=Sun Microsystems Inc.)
Remote Addr: 192.168.0.106
Remote Host: abc
Character Encoding: null
Content Length: -1
Content Type: null
Auth Type: null
HTTP Method: GET
Path Info: null
Path Trans: null
Query String: null
Remote User: null
Session Id: To1010mC466113890241879At
Request URI: /c.jsp
Servlet Path: /c.jsp
Accept: */*
Host: 192.168.0.1:8080
Referer : n
Scheme: http
Server Name: 192.168.0.1
Server Port: 8080
Protocol: HTTP/1.1

你可能感兴趣的:(c,jsp,windows,servlet,Scheme)