漆黑的羊驼 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 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊