responseoutputstream的输出问题
来源:互联网 发布:铁塔平台 登录域名 编辑:程序博客网 时间:2024/05/22 10:49
在客户端那边打印中文
package response;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ResponseDemo1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String data = "中国";
response.setHeader("Content-type","text/html;charset = UTF-8");//发送一个相应头来控制客户端浏览器该用那种方式打开
OutputStream out = response.getOutputStream();
out.write(data.getBytes("UTF-8"));// 保险一点
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
2.还有一种方法是通过html中的<meta>标签来控制浏览器的编码方式
private void test2(HttpServletResponse response) throws IOException,
UnsupportedEncodingException {
String data = "中国";
OutputStream out = response.getOutputStream();
out.write("<mate http-equiv='content-type' content = 'text/html;charset = UTF-8'>".getBytes());
out.write(data.getBytes("UTF-8"));
}
3.其实做下载挺简单的(写错了就下载)
private void test1(HttpServletResponse response) throws IOException,
UnsupportedEncodingException {
String data = "中国";
response.setHeader("Content-type", "text/html,charset = UTF-8");// 把分号写成了逗号
OutputStream out = response.getOutputStream();
out.write(data.getBytes("UTF-8"));// 保险一点
}
5.输出数字的问题
“1”和1 完全是两回事,我们想看到数字1我们需要写的是“1”(字符1)。
package response;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ResponseDemo1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String data = "中国";
response.setHeader("Content-type","text/html;charset = UTF-8");//发送一个相应头来控制客户端浏览器该用那种方式打开
OutputStream out = response.getOutputStream();
out.write(data.getBytes("UTF-8"));// 保险一点
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
2.还有一种方法是通过html中的<meta>标签来控制浏览器的编码方式
private void test2(HttpServletResponse response) throws IOException,
UnsupportedEncodingException {
String data = "中国";
OutputStream out = response.getOutputStream();
out.write("<mate http-equiv='content-type' content = 'text/html;charset = UTF-8'>".getBytes());
out.write(data.getBytes("UTF-8"));
}
3.其实做下载挺简单的(写错了就下载)
private void test1(HttpServletResponse response) throws IOException,
UnsupportedEncodingException {
String data = "中国";
response.setHeader("Content-type", "text/html,charset = UTF-8");// 把分号写成了逗号
OutputStream out = response.getOutputStream();
out.write(data.getBytes("UTF-8"));// 保险一点
}
5.输出数字的问题
“1”和1 完全是两回事,我们想看到数字1我们需要写的是“1”(字符1)。
0 0
- responseoutputstream的输出问题
- ImageIO.write(image, "JPEG", responseOutputStream);
- 格式输出的问题
- 数组的输出问题
- who的输出问题
- wchar_t 的输出问题
- Qstring的输出问题
- 百分号的输出问题
- 字符数组输出的问题
- wprintf 输出中文的问题
- Struts2 的XSLTResult输出问题
- 有关printf输出的问题
- 汉字输出乱码的问题
- HttpServletResponse输出中文的问题
- Servlet的中文输出问题
- 标准输出的缓存问题
- 字符数组的输出问题
- jstl输出遇到的问题
- jdbc.jar连接Sql Server 2012数据库
- IDEA 选择器及标识符
- c++字符串简单加密的方法。推荐
- Matlab图像处理零散知识点
- 上楼梯
- responseoutputstream的输出问题
- 实战演练:用gulp+webpack构建用户登录(1)
- ARM 全局页表与二级页表转换调试
- 排队买饭
- Matplot 绘图中文乱码解决方案
- 散列表
- response的write输出问题
- Java String 源码浅析
- UVA 729 The Hamming Distance Problem