网页编码
2015-08-11 19:58
399 查看
serverlet的网页编码
Serverlet的编码思想:网页的编码都是iso-8859-1而一般我们所用的编程平台都是utf-8这样之间的传递就会出现乱码,就得需要编码转换,转换的思想将的到的编码,转换为最小单位编码,byte,然后在 转换为自己想要的编码。举个列子,首先得到的是网页的数据,iso-8859-1的编码,我要得到utf-8,然后得到后在给网页传输一个数据。
Serverlet的编码思想:网页的编码都是iso-8859-1而一般我们所用的编程平台都是utf-8这样之间的传递就会出现乱码,就得需要编码转换,转换的思想将的到的编码,转换为最小单位编码,byte,然后在 转换为自己想要的编码。举个列子,首先得到的是网页的数据,iso-8859-1的编码,我要得到utf-8,然后得到后在给网页传输一个数据。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String username=request.getParameter("username");//得到的网页的uername, String password=request.getParameter("password"); username=Encoding.encoding(username);//通过编写的方法,进行转换 System.out.println("用户名"+username+"\n"+"密码"+password); /** * 然后在给浏览器数据 */ response.setHeader("content-type","text/html;charset=utf-8");//让浏览器以utf-8格式解析 response.getWriter().append("用户名:"+username); response.getWriter().println("<br>"); response.getWriter().append("密码 :"+password); } 编码转换的代码 public class Encoding { public static String encoding(String s) { try { byte[] array = s.getBytes("ISO-8859-1"); s = new String(array, "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; } }
相关文章推荐
- Orace查询数据出现乱码的问题解决思路
- oracle em 按钮乱码解决办法及em网页变成英文
- C#读取中文文件出现乱码的解决方法
- mysql命令提示行连接乱码的解决
- XML指南——XML编码
- C#中字符串编码处理
- ExtJS中文乱码之GBK格式编码解决方案及代码
- 程序员趣味读物 谈谈Unicode编码
- 文本文件编码方式区别
- Jquery乱码的一次解决过程 图解教程
- C语言安全编码之数值中的sizeof操作符
- C#实现获取文本文件的编码的一个类(区分GB2312和UTF8)
- 解决realplayer11中文正式版网页右键乱码问题embed_cn.dll
- VC中BASE64编码和解码使用详解
- 计算机中的字符串编码、乱码、BOM等问题详解
- Base64编码解码原理及C#编程实例
- C#编码好习惯小结
- php+AJAX传送中文会导致乱码的问题的解决方法
- Discuz!nt 源文件变成乱码的解决方法
- 深入理解Python字符编码 推荐