doget dopost 过滤器 乱码

为了解决乱码问题,在web.xml中定义的过滤器ContextLoaderListener只适用于servlet的dopost方法,而对doget方法不适用。

这里提供一种思路可以参考:

if (req.getMethod().equals( "POST")) {
                         while (tEnumer.hasMoreElements()) {
                                String tStr = (String) tEnumer.nextElement();
                                 // log.info(tStr + "-[" + req.getParameter(tStr) + "]");
                                paramsUtil.put(tStr, req.getParameter(tStr));
                        }
                } else if (req.getMethod().equals( "GET")) {
                         //get方法不支持web.xml中的过滤器配置
                         while (tEnumer.hasMoreElements()) {
                                String tStr = (String) tEnumer.nextElement();
                               
                                 try {
                                        paramsUtil.put(tStr, new String(req.getParameter(tStr).getBytes( "ISO-8859-1"), "UTF-8"));
                                } catch (UnsupportedEncodingException e) {
                                        log.debug("",e);
                                }
                        }
                }

你可能感兴趣的:(职场,乱码,休闲)