session、request和response常用方法

void setAttribute(String attribute, Object value)     设置Session属性。value参数可以
为任何Java Object。通常为Java Bean。value信息不宜过大
String getAttribute(String attribute) 返回Session属性
Enumeration getAttributeNames() 返回Session中存在的属性名
void removeAttribute(String attribute) 移除Session属性
String getId() 返回Session的ID。该ID由服务器自动创建,不会重复
long getCreationTime() 返回Session的创建日期。返回类型为long,常被转化为Date类型,例如:Date createTime = new Date(session.getCreationTime())
long getLastAccessedTime() 返回Session的最后活跃时间。返回类型为long
int getMaxInactiveInterval() 返回Session的超时时间。单位为秒。
超过该时间没有访问,服务器认为该Session失效
void setMaxInactiveInterval(int second) 设置Session的超时时间。单位为秒
void putValue(String attribute, Object value) 不推荐的方法。已经被setAttribute
(String attribute, Object Value)替代
Object getValue(String attribute) 不被推荐的方法。已经被getAttribute
(String attr)替代

Request类


 1. setAttribute()在Request域中存储数据
 2. setCharacterEncoding()设置请求参数的编码方式,只对post请求有效
 3. getMethod()获取请求类型
 4. getParameter()获取指定请求参数值
 5. getParameterNames()获取所有请求参数,返回一个Enumeration枚举类
 6. getAttribute()获取域中存储的数据
 7. getAttributeNames()获取域中所有数据,返回一个Enumeration枚举类
 8. getContextPath()返回当前WEB项目相对路径
 9. getCookies()获取所有Cookie,返回一个Cookie数组
 10. getRequestDispatcher()获取转发器,参数路径以/打头,代表WebRoot(当前WEB项目根目录)
 11. getSession()获取Session对象



Response类


 1. setContentType()告知浏览器数据类型
 2. setCharacterEncoding设置Response的编码方式
 3. setHeader()设置消息头
 4. setStatus()设置状态吗
 5. addCookie()添加Cookie
 6. sendRedirect()重定向
 7. getOutputStream()获取通向浏览器的字节流(同一次请求处理中,字节流和字符流不能同时存在)
 8. getWriter()获取通向浏览器的字符流(同一次请求处理中,字节流和字符流不能同时存在)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值