servlet乱码问题~~~
servlet出现乱码改了也不行!!
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GB2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
加上这两行也不行啊,为什么呢??
怎么改呀
搜索更多相关主题的帖子:
乱码 servlet
----------------解决方案--------------------------------------------------------
直接new String (request.getParameter("要获取的对象").getBytes("ISO-8859-1"),"gbk");
再不就写过滤器
其实就两行核心代码
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain arg2) throws IOException, ServletException {
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
arg2.doFilter(request,response);
}
记住过滤器要继承Filter
----------------解决方案--------------------------------------------------------
打快了,打错了,是要implements Filter 实现这个接口
----------------解决方案--------------------------------------------------------