您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

servlet解决中文乱编的问题(7)

来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:48 点击:

   throws ServletException, IOException {
  response.setContentType("text/html;charset=GBK");
  String newname = new String(request.getParameter("username").getBytes(
    "ISO-8859-1"), "GBK");
  PrintWriter out = response.getWriter();
  out.print("<html><head></head><body>GET方式提交<br/><h2>" + newname);
  out.print("</h2></body></html>");
  out.close();
 }

 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/html;charset=GBK");
  //request.setCharacterEncoding("GBK");
  System.out.println("调用doPost");
  String newname = request.getParameter("username");
  PrintWriter out = response.getWriter();
  out.print("<html><head></head><body>POST方式提交<br/><h2>" + newname);
  out.print("</h2></body></html>");
  out.close();
 }
}

 
摘自 Mars学IT
 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • JSP与Servlet
  • 自己动手写MiniBBS系列(基本篇)之用户登录
  • JSP取当前日期
  • JDBC 入门(一)
  • 打开一个jsp页面默认查询所有数据,调用action
  • 使用JSP标签库验证用户的输入(2)完
  • WIN98/2000下的jsp服务器
  • 自定义JSP标签(tag)浅议
  • Struts学习傻瓜式入门篇
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1