漆黑的羊驼 2018-12-22 16:32 采纳率: 0%
浏览 2168

经servlet跳转后,跳转后的jsp页面原页面上的中文问号乱码

学生党,在做期末的课程设计

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        execute(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        execute(req, resp);
    }

    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if (request.getParameter("ID").equals("admin") && request.getParameter("password").equals("admin")){
            request.getRequestDispatcher("../administrator.jsp").forward(request,response);
        }else {
            StudentAccount account = new StudentAccount();
            AdminDAO adminDAO = new AdminDAO();
            account.setID(Integer.valueOf(request.getParameter("ID")));
            account.setPassword(request.getParameter("password"));
            StudentAccount stu = adminDAO.findStuByID(account.getID());
            PrintWriter writer = response.getWriter();
            if (stu == null) {
                writer.print("<script language='javascript'>" +
                        "alert('The account does not exist!');" +
                        "window.location.href='../index.jsp';" +
                        "</script>");
            } else {
                if (account.getID() == stu.getID() && account.getPassword().equals(stu.getPassword())){
                    request.getRequestDispatcher("../studentInfo.jsp").forward(request, response);
                }else {
                    writer.print("<script language='javascript'>" +
                            "alert('Wrong password!');" +
                            "window.location.href='../index.jsp';" +
                            "</script>");
                }
            }

        }
    }

这是我的LoginServlet,用于登录,然后奇怪的是,假如是登录到administrator.jsp页面的话是正常的,但是跳转到studentInfo页面上,原页面上的中文就直接乱码了,图片说明
然后就是直接进入那个页面的话,中文就是没有乱码的
图片说明
萌新求解

  • 写回答

2条回答 默认 最新

  • 魔龍 2018-12-22 08:54
    关注

    解决post请求中的中文乱码问题:
    在doGet()方法里面加入:request.setCharacterEncoding("utf-8");

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用