response内置对象
来源:互联网 发布:java编写倒99乘法表 编辑:程序博客网 时间:2024/06/06 09:05
response对象包含响应客户端请求的有关信息,但是在jsp中很少使用它,它是HttpServletResponse类的实例,response对象具有页面作用域,即访问一个页面时,该页面内的response对象只能对这次访问有效,其他页面的response对象对当前页面无效,常用方法如下:
1、String getCharacterEncoding(),返回响应的何种字符编码
2、void setContentType(String type),返回响应的MIME类型
type:类似“text/html;charset=utf-8”,一般设置在输出字符之前
3、PrintWriter getWrite()可以返回一个可以向客户端输出字符的对象
这里注意与内置对象out的区别,如下例子:
out.println("<h1>response内置对象</h1>");out.println("<hr>")**out.flush();**PrintWriter outer = response.getWriter();outer.println("大家好,我是response对象生成的输出流outer");response.sendRedirect("reg.jsp");
以上输出时打印的时候,outer输出流虽然后面生成。但是先于内置对象out之前输出,要解决这个问题,只需要调用out的flush方法,清空缓冲区,在清空之前会强制输出里面内容。
4、sendRedirect(String location),重新定向客户端的请求,与请求转发区别请看request.
以上例子中即可跳转到reg.jsp页面。相当于发送了一个新的请求,发送到reg.jsp页面。
ps:该过程跳转速度过快,看不到输出流输出的内容即会跳转页面。
0 0
- 内置对象Response
- JSP内置对象----response
- JSP内置对象----response
- JSP内置对象---response
- response内置对象
- JSP内置对象response
- JSP内置对象---response
- JSP 内置对象Response
- jsp内置对象response
- JSP内置对象response
- response内置对象
- 内置对象:response
- 内置对象 response
- jsp内置对象---response对象
- jsp内置对象response对象
- JSP内置对象之response
- 06JSP内置对象response
- ASP内置对象详解之Response对象
- [LeetCode]Single Number
- 轻松自动化---selenium-webdriver(python) (二)
- 对象中间件--CORBA开发练习
- js闭包
- Reorder List
- response内置对象
- 堆排序 HeapSort
- Android5.x新特性之 Toolbar和Theme的使用
- Unity导出的iOS项目出错Use of undeclared identifier 'GL_BGRA_EXT'
- openstack快照分析
- 使用EXCEL设置“下拉菜单”选项功能
- 进程和线程关系及区别
- AndroidAnnotations——Injecting FragmentArg注入Fragment参数
- mysql忘记root密码windows下解决方法