request对象的常用方法
方法名称 | 说明 |
---|---|
String getParameter(String name) | 根据页面表单组件名称获取页面提交数据 |
String[] getParameterValues(String name) | 获取一组以相同名称命名的表单组件提交的数据 |
void setCharacterEncoding(String charset) | 指定每个请求的编码,在调用request.getParameter()方法之前进行设定,可以用于解决中文乱码问题 |
PequestDispatcher getRequesDispatcher(String path) | 返回一个javax.servlet.RequestDispatcher对象,该对象的forward()方法用于转发请求 |
案例
response对象的常用方法
方法名称 | 说明 |
---|---|
void addCookie(Cookie cookie) | 向客户端添加Cookie |
void setContentType(String type) | 设置HTTP响应的contentType类型 |
void setCharacterEncoding(String charset) | 设置响应所采用的字符编码类型 |
void sendRedirect(String location) | 将请求重新定位到一个新的URL上 |
session对象的常用方法
方法名称 | 说明 |
---|---|
String getId() | 获取sessionid |
void setMaxInactiveInterval(int interval) | 设定session的非活动时间 |
int getMaxInactiveInterval() | 获取session的有效非活动时间,以秒为单位 |
void invalidate() | 设置session对象失效 |
void setAttribute(String key,Object value) | 以key/value的形式将对象保存到session中 |
Object getAttribute(String key) | 通过key获取session中保存的对象 |
void removeAttribute(String key) | 从session中删除指定key对应的对象 |