respone对象
response对象
response对象
JSP内置对象/response对象
response对象:
response对象:响应客户请求
response.getWriter()创建输出流对象(PrintWriter://输出流类型)
例:PrintWriter outer=response.getWriter();//生成的outer和out内置对象区别是这个总是在out之前输出
out.flush();//清空缓冲区的同时向浏览器强制输出缓冲区内容
response.sendRedirect("reg.jsp");请求重定向,跳转到新的页面
Jsp Response对象
response对象
response对象
response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。它是HttpServletResponse类的实例。response对象具有页面作用域,即访问一个页面时,该页面的response对象只能对这次访问有效,其他页面的response对象对当前页面无效。常用方法如下:
***String getCharacterEncoding() 返回响应用的是何种字符编码
***void setContentType(String type) 设置响应的MIME类型
***PrintWriter getWriter() 返回可以向客户端输出字符的一个对象(注意比较:PrintWriter与内置out对象的区别)
***sendRedirect(java.lang.String location)重新定向客户端的请求
Eclipse 中需要手动import java.io.* , PrinterWriter才能使用。
<%@ page import="java.io.*" %>
response对象
response获得的writer对象,给浏览器输出流的对象,在打印的时候提前于out的内置对象
登陆数据错误则重新定向
Jsp内置对象之response对象:
常用方法如下:
String getCharacterEncoding() 返回响应用的是何种字符编码。
void setContentType(String type) 设置响应的MIME类型。
PrintWriter getWriter() 返回可以向客户端输出字符的一个对象(注意比较 :PrintWriter与内置out对象的区别 PrintWriter方法 会优先于out输出,在out输出下面写”out.flush();“即可解决)
sendRedirect(Java.lang.String location) 重新定向客户端的请求。
response常用的方法
请求重定向
不能够有out.close()或者out.flush()操作
会抛出异常
response.getWriter()输出内容总是在out之前,但可以使用out.flush()来提前输出。
response.sendRedirect("...");重定向之前,不能够有out.close()或者out.flush()操作。否则会有java.lang.IllegalStateException
向客户端输出字符串对象, 而且先于jspWriter,使用out.flush()来避免
response对象有页面作用域:即访问一个页面时,该页面内的response对象只能对这次访问有效,其它页面的response对象对当前页面无效。
String getCharacterEncoding()返回响应的是何种字符编码
void setContentType(String type) 设置响应的MIME类型
PrintWriter getWriter() 返回可以向客户端输出字符的一个对象,输出提前于内置的out对象
sendRedirect 重新定向客户端的请求
response对象有页面作用域
String getCharacterEncoding()返回响应的是何种字符编码
void setContentType(String type) 设置响应的MIME类型
PrintWriter getWriter() 返回可以向客户端输出字符的一个对象,输出提前于内置的out对象
sendRedirect 重新定向客户端的请求
常用的resonse对象
笔记1jsp内置对象
response对象
response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。他是HttpServletResponse类的实例。response对象具有页面作用域,即访问一个页面时,该页面内的response对象只能对这次访问有效,其它页面的response对象对当前页面无效。常用方法:
String getCharacterEncoding() 返回响应用的是何种字符编码
void setContentType(String type) 设置响应的MIME类型
PrintWriter getWriter() 返回可以向客户端输出字符的一个对象
sendRedirect(java.lang.String location) 重新定向客户端的请求
response对象
response对象:
获取响应的字符编码:getCharacterEncoding
设置响应的MIME类型:setContentType
返回可以输出的字符的对象:PrintWriter outer=response.getWriter();
请求重定向:response.sendRedirect("页面")
response内置对象
response对象的getWrite()方法 较out对象的println()方法的优先级要更高
JSP内置对象——response对象
reponse对象包含了想赢刻骨请求的有关信息,但在JSP中很少直接用到它。它是HttpServletResponse类的实例。response对象具有页面作用域,即访问一个页面时,该页面内的response对象只对这次访问有效,其它页面的response对象对当前页面无效
常用方法如下
response的sendRedirect()方法就是模拟用户重新发起请求,并传递给此方法参数,此参数指定了代表浏览器请求的页面。
对它的具体讲解见下一节。
解决PrintWriter对象的pintln()优先级高的问题,用out对象的flush()方法,同时,也确认了flush方法的具体机制:
本例中,将其上面两个语句(见截图)的内容清理出缓冲区,同时,将它们在客户端的浏览器上显示出来,这样,此语句之前的内容就确保先显示出来了。flush起到一个分阶段的作用。