zoukankan      html  css  js  c++  java
  • doGet和doPost的数据的获取

    在Servlet里面,其中有一种方式是通过
    <a href="<%=request.getContextPath() %>/search?username=<%=name %>" title="查看个人资料" target="_blank">
    来提交信息,在点击点击链接的时候,username的数据传给链接到的页面,在打开的页面里,因为他是一个doGet方法,所以汉字可能会产生乱码,这时候在接受页面要通过
    String notUsername = req.getParameter("username");
    String username = new String(notUsername.getBytes("ISO-8859-1"),"UTF-8");

    的方式,把接受过来汉字通过UTF-8的编码方式进行解码,这样才能保证得到的文字不出现乱码。

    但是,在正常的doPost页面,不能通过这种方式,而是应该使用
    String username = req.getParameter("username");
    的方式来进行数据的获取,各种方式必须使用对应的格式,否则会产生乱码。
    综上,在doPost方式中,应该使用
    String username = req.getParameter("username");
    在doGet方式中,应该使用
    String notUsername = req.getParameter("username");
    String username = new String(notUsername.getBytes("ISO-8859-1"),"UTF-8");
  • 相关阅读:
    搜索1011
    搜索1008(二分)
    贪心算法专题总结
    贪心算法1002
    c++笔记
    贪心算法1017
    贪心算法1008
    贪心算法1013
    Ubuntu中 sudo update与sudo upgrade的作用及区别
    requirejs 扩展,支持脚本资源预加载
  • 原文地址:https://www.cnblogs.com/hourui/p/doGet-doPost.html
Copyright © 2011-2022 走看看