request对象2

request方法(下)
JSP内置对象/request对象

补:
***int getServerPort() 返回服务器接收此请求所用的端口号
***String getCharacterEncoding() 返回字符编码方式
***void setCharacterEncoding() 设置请求的字符编码方式;
***String getRemoteAddr() 返回发送此请求的客户端IP地址
***String getRealPath(String path)返回一虚拟路径的真实路径
***int getContentLength() 返回请求提的长度(以字节数)
***String request.getContextPath() 返回上下文路径
request对象
客户端的请求信息被封装在reques对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。request对象具有请求域,即完成客户端的请求之前,该对象一直有效。常用方法如下:
***String getParameter(String name) 返回name指定参数的参数值
***String[] getParameterValues(String name) 返回包含参数name的所有的数组
***void setAttribute(String, Object);存储此请求中的属性值
***object getAttribute(String name) 返回指定属性的属性值
***String getContentType() 得到请求体的MIME类型
***String getProtocol() 返回请求用的协议类型及版本号
***String getServerName() 返回接受请求的服务器主机名
Jsp内置对象之request对象:
常用方法如下:
String getParameter(String name) 返回name指定参数的参数值,即获取命名为“name”的值。
String[] getParameterValues(String name) 返回包含参数name的所有值的数组,即获取命名为“name”的数组中的所有值。
void setAttribute(String,Object) 存储此请求中的属性,"String"为键,“Object”为存储的值,可以用getAttribute(“键”)来获取“Object”位置所对应的值。
object getAttribute() 返回指定属性的属性值。
String getContentType() 得到请求体的MIME类型。
String getProtocol() 返回请求用的协议类型及版本号。
String getServerName() 返回就收请求的服务器主机名。
int getServerPort() 返回服务器接收此请求所用的端口号。
String getCharacterEncoding() 返回字符编码方式。
void setCharacterEncoding() 设置请求的字符编码方式。
int getContentLength() 返回请求体的长度(以字节数)
String getRemoteAddr() 返回发送此请求的客户端IP地址。
String getRealPath(String path) 返回一虚拟路径的真实路径。
String request.getContextPath() 返回上下文路径。
request常用方法
request对象
request.getAttribute("password","123456");
request.setAttribute("password");
请求体的MIME类型:<%=request.getContentType()%><br>
协议类型及版本号:<%=request.getProtocol() %><br>
服务器主机名:<%=request.getServerName() %><br>
服务器端口号:<%=request.getServerPort() %><br>
请求文件长度(字节):<%=request.getContentLength() %><br>
请求客户端的IP地址:<%=request.getRemoteAddr() %><br>
请求的真实路径:<%=request.getRealPath("request.jsp") %><br>
请求的上下文路径:<%=request.getContextPath() %><br>
JSP内置对象
没看懂这个setAttribute()和getAttribute()有什么用:自己设的自己又取。这是要干嘛???
request对象
int getServerPort() 返回服务器接受此请求所用的端口号
String getCharacterEncoding() 返回字符编码方式
void setCharacterEncoding() 设置请求的字符编码方式
int getContentLength() 返回请求体的长度(以字节数)
String getRemoteAddr() 返回发送此请求的客户端IP地址
String getRealPath(String path) 返回一虚拟路径的真实路径
String request.getContextPath() 返回上下文路径
request对象(2)
存储此请求中的指定属性的属性值:<% request.setAttribute("password", "123456"); %>
返回此请求中的指定属性的属性值:<%=request.getAttribute("password") %>
请求的MIME类型:<%=request.getContentType() %>
协议类型及版本号:<%=request.getProtocol() %>
服务器主机号:<%=request.getServerName() %>
服务器端口号:<%=request.getServerPort() %>
int getServerPort():返回服务器接受此请求所用的端口号
String getCharacterEncoding():返回字符编码方式
void setCharacterEncodign():设置请求的字符编码方式
int getContentLength():返回请求体的长度(以字节数)
String getRemoteAddr():返回发送此请求的客户端IP地址
int getServerPort():返回服务器接受此请求所用的端口号
String getCharacterEncoding():返回字符编码方式
void setCharacterEncodign():设置请求的字符编码方式
int getContentLength():返回请求体的长度(以字节数)
String getRemoteAddr():返回发送此请求的客户端IP地址
String getRealPath(String path):返回虚拟路径的真实路径
request对象


存储此请求中的指定属性的属性值:<% request.setAttribute("password", "123456"); %>
返回此请求中的指定属性的属性值:<%=request.getAttribute("password") %>
请求的MIME类型:<%=request.getContentType() %>
协议类型及版本号:<%=request.getProtocol() %>
服务器主机号:<%=request.getServerName() %>
服务器端口号:<%=request.getServerPort() %>
int getServerPort():返回服务器接受此请求所用的端口号
String getCharacterEncoding():返回字符编码方式
void setCharacterEncodign():设置请求的字符编码方式
int getContentLength():返回请求体的长度(以字节数)
String getRemoteAddr():返回发送此请求的客户端IP地址
int getServerPort():返回服务器接受此请求所用的端口号
String getCharacterEncoding():返回字符编码方式
void setCharacterEncodign():设置请求的字符编码方式
int getContentLength():返回请求体的长度(以字节数)
String getRemoteAddr():返回发送此请求的客户端IP地址
String getRealPath(String path):返回虚拟路径的真实路径
ruquest对象的setAttribute()方法就是代替用户输入,凭空给request设置一对属性及其对应值。
getAttribute()则是取出某个名称属性的值,要传入属性名作为参数。
request的其它方法示例-结果
request的其它方法示例-代码
区分表达式 <%=表达式%> 还是脚本<% Java代码 %> 可以简单认为表达式没有分号 ; , 脚本要有分号来区分语句
request常用api案例
request方法
request对象
【a】request对象的getAttribute和setAttribute不能用于页面间存值和取值,适用于单个页面间存值和取值。



存储此请求中的指定属性的属性值:<% request.setAttribute("password", "123456"); %>
返回此请求中的指定属性的属性值:<%=request.getAttribute("password") %>
请求的MIME类型:<%=request.getContentType() %>
协议类型及版本号:<%=request.getProtocol() %>
服务器主机号:<%=request.getServerName() %>
服务器端口号:<%=request.getServerPort() %>
请求文件的长度:<%=request.getContentLength() %>
请求客户端的IP地址:<%=request.getRemoteAddr() %>
请求的真是路径:<%=request.getRealPath("request.jsp") %>
请求的上下文路径:<%=request.getContextPath() %>
request常用方法:
int getServerPort():返回服务器接受此请求所用的端口号
String getCharacterEncoding():返回字符编码方式
void setCharacterEncodign():设置请求的字符编码方式
int getContentLength():返回请求体的长度(以字节数)
String getRemoteAddr():返回发送此请求的客户端IP地址
String getRealPath(String path):返回虚拟路径的真实路径
int getServerPort():返回服务器接受此请求所用的端口号
String getCharacterEncoding():返回字符编码方式
void setCharacterEncodign():设置请求的字符编码方式
int getContentLength():返回请求体的长度(以字节数)
String getRemoteAddr():返回发送此请求的客户端IP地址
String getRealPath(String path):返回虚拟路径的真实路径
String request.getContextPath():返回上下文路径
JSP内置对象 request对象 int getServerPort();//返回服务器接受此请求所用的端口号 String getCharacterEncoding();//返回字符编码方式 void setCharacterEncodinng();//设置请求的字符编码方式 int getContentLength();//返回请求体的长途(以字节数) String getRemoteAddr();//返回发送此请求的客户端IP地址 String getRealPath(String path);//返回虚拟路径的真实路径 String request.getContextPath();//返回上下文路径 IP地址为IPv6本地环回地址。
int getServerPort() 返回服务器接受此请求所用的端口号
String getCharacterEncoding() 返回字符编码方式
void setCharacterEncoding()设置请求的字符编码方式
int getContentLength()返回请求体的长度(以字节数)
String getRemoteAddr() 返回发送此请求的客户端IP地址
String getRealPath(String path) 返回一虚拟路径的真实路径
String request.getContextPath() 返回上下文路径
request实例包含的方法:
