doGet和doPost乱码

来源:互联网 发布:网络动漫黑名单 解禁 编辑:程序博客网 时间:2024/05/16 05:28

doGet和doPost,doPost可以用doGet代码解决反之不能

public class GetPostMethod extends HttpServlet {    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        String username = request.getParameter("username");        username = new String(username.getBytes("iso-8859-1"), "utf-8");        System.out.println(username);    }    public void doPost(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        request.setCharacterEncoding("utf-8");        String username = request.getParameter("username");        System.out.println(username);    }}

html页面

    <form action="/d_response/getpost" method="get">        <input type="text" name="username">        <input type="submit" value="提交">    </form>    <form action="/d_response/getpost" method="post">        <input type="text" name="username">        <input type="submit" value="提交">    </form>
0 0
原创粉丝点击