【JSP开发】response输出中文和数据的问题
2015-01-30 11:29
375 查看
package cn.edu.Response; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; //servlet中用OutputStream输出中文和数据的问题 public class ResponseDemo1 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { test2(response); } private void test1(HttpServletResponse response) throws IOException, UnsupportedEncodingException { //程序以什么码表输出了,程序就一定要控制浏览器以什么码表打开 //text/html;如果写成text/html,的话浏览器会提示下载 response.setHeader("Content-type", "text/html;charset=UTF-8"); String data="中国"; ServletOutputStream out =response.getOutputStream(); //浏览器默认的字节编码是gb2312 out.write(data.getBytes("UTF-8")); } private void test2(HttpServletResponse response) throws IOException, UnsupportedEncodingException { String data="中国"; OutputStream out =response.getOutputStream(); //用html技术中meta标签模拟了一个http响应头,来控制浏览器的行为 out.write("<meta http-equiv='content-type' content='text/html;charset=UTF-8'>".getBytes()); out.write(data.getBytes("UTF-8")); out.write((1+"").getBytes());//这样写1才会出来 } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } }
相关文章推荐
- 【JSP开发】通过response的writer流输出数据的问题
- JavaEE中用response向客户端输出中文数据乱码问题分析
- JavaEE中用response向客户端输出中文数据乱码问题分析
- 解决Java Web开发中Jsp存储读取MySQL数据中文乱码的问题
- response的Writer输出数据的问题输出中文的乱码问题
- 解决Java Web开发中Jsp存储读取MySQL数据中文乱码的问题
- JavaEE中用response向客户端输出中文数据乱码问题分析
- 解决Java Web开发中Jsp存储读取MySQL数据中文乱码的问题
- JavaEE中用response向客户端输出中文数据乱码问题分析
- response小结(一)——用response向客户端输出中文数据(乱码问题分析)
- jsp页面添加中文数据到mysql数据库乱码问题
- 解决JSP数据输入中文乱码问题
- Jsp输出excel文档和中文乱码问题的解决
- 解决JSP开发Web程序中的中文问题
- 解决JSP开发Web程序中的中文问题
- 使用JSP开发应用程序时的编码(中文等乱码)问题的建议解决方案(包括接受request和数据库操作)
- 解决JSP开发Web程序中的中文问题
- jsp中response.sendRedirect()的中文参数乱码问题
- 用jsp动态输出excel文档和中文乱码问题的解决
- 解决jsp开发中的所有中文问题 对serverlet设置过滤器