Javaweb数据库中 出现乱码问题解决

当在jsp页面中输入数据中文字符会出现乱码情况

 

 问题出在servlet的代码上在doget中添加

request.setCharacterEncoding("utf-8");

时可正常输入中文字符

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
             request.setCharacterEncoding("utf-8");
        if("addhouse".equals(request.getParameter("method"))) {addhouse(request,response);}
        else if("register".equals(request.getParameter("method")))register(request,response);
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

 

posted @ 2021-12-04 10:57  Rebz  阅读(122)  评论(0编辑  收藏  举报