getRequestDispatcher().include(); 乱码的解决办法

  • Post author:
  • Post category:其他


我用filter做个session的查验(看有没有登陆。防止直接访问后台),比如说没有登陆的session,我要把他转发到首页上去。我用了

if(path.contains(“adminManagePage”)|path.contains(“studentQueryPage.jsp”)){


//System.out.println(“拦截到页面了”);

//System.out.println(info);

if(info==”success”){


chain.doFilter(request, response);

}else{


//hsr.getRequestDispatcher(“index.jsp”).forward(request, response);

//存在页面空白问题

//hsrp.sendRedirect(“index.jsp”);


response.setCharacterEncoding(“UTF-8”);


hsr.getRequestDispatcher(“index.jsp”).include(request, response);

}

}

转发呢,会出现地址不跳转的问题,包含也是。这里要说的是使用包含会出现中文的乱码。原因是直接去页面,jsp定义的编码没有效果,需要自己手动设置一下响应的编码。



版权声明:本文为qq_35659877原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。