Response功能(一)
发布时间:2022-09-16 11:40:06 224 相关标签: # html# 服务器# 数据# 服务器
//1. 设置状态码为302
response.setStatus(302);
//2。重定向
String contextPath = request.getContextPath();
response.sendRedirect(contextPath+"http://wwww.baidu.com");
//3----------转发
request.getRequestDispatcher("/ demo2").forward(request,response);
//4--------获取字符输出流
//设置流的默认编码:ISO-8859-1 设置为utf8-
// response.setCharacterEncoding("utf-8");
//告诉浏览器,服务器发送的消息体数据的编码,建议浏览器使用该编码解码
// response.setHeader("content-type","text/html;charset=utf-8");
//简单的方式,设置编码
response.setContentType("text/html;charset=utf-8");
//获取字符输出流
PrintWriter pw = response.getWriter();
//输出数据
pw.write("hello world");
pw.write("你好,reponse");
//5---------获取字节输出流
ServletOutputStream os = response.getOutputStream();
//输出数据
os.write("你好".getBytes());
文章来源: https://blog.51cto.com/u_15754099/5585506
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报