处理中文乱码 并 写入cookie中
/** * cookie写入....常用链接 * 写cookie 模式:(language)en_US_menu=url,url,url.... * @return String **/public String writeLinks(){//获取语言 没有 就从cookie中读取if(null==locale_language||"".equals(locale_language)){locale_language=getLanguage();}String key=locale_language+"_menu";HttpServletResponse response=ServletActionContext.getResponse();Cookie cookie=null;try {links=new String(links.getBytes("iso-8859-1"), "utf-8"); cookie=new Cookie(key,URLEncoder.encode(links, "utf-8"));} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}//设置cookie的有效日期 以秒为单位cookie.setMaxAge(365*24*60*60);response.addCookie(cookie);return readLinks();}/** * cookie读取....常用链接 * 读cookie 通过 key:(language)en_US_menu=value:noteName_/wmba/user/user_doCreate.action * @return String * **/public String readLinks(){//获取语言 没有 就从cookie中读取if(null==locale_language||"".equals(locale_language)){locale_language=getLanguage();}//根据语言拼凑cookie中菜单的keyString key=locale_language+"_menu";HttpServletRequest request=ServletActionContext.getRequest();//修改常用链接 时 传递了常用链接if(null==links||"".equals(links)){//获得客户端所有的cookie信息Cookie[] cookies=request.getCookies();//循环遍历所有的cookie 找到 根据key对应的cookiefor(Cookie ck : cookies){if(ck.getName().equals(key)&&null!=ck.getValue()&&!"".equals(ck.getValue())){try {links=URLDecoder.decode(ck.getValue(), "UTF-8");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}//list 保存常用连接linkList=new ArrayList<EsbAdminMenuInfo>();//从cookie中找到对应的常用链接 否则去数据库中的链接if(links != null &&!"".equals(links)){String[] array_links=links.split(",");for(String link : array_links){EsbAdminMenuInfo menu=new EsbAdminMenuInfo();menu.setNoteName(link.substring(0,link.indexOf("_")));menu.setUrl(link.substring(link.indexOf("_")+1));linkList.add(menu);}}else{//从配置文件中加载而来int linkCount=Integer.valueOf(ServletActionContext.getContext().getApplication().get("linkCount").toString());//设置查询条件 EsbAdminUserInfo userInfo=(EsbAdminUserInfo)ServletActionContext.getRequest().getSession().getAttribute("user");//得到所有的菜单List<EsbAdminMenuInfo> menusAll=this.loadingMenu(userInfo);//过滤 linkCount个 并 只要有url的菜单for(int i=0;i<menusAll.size();i++){if(menusAll.get(i).getUrl()!=null&&!("".equals(menusAll.get(i).getUrl()))){if(linkList.size()<linkCount){linkList.add(menusAll.get(i));}}}}return "index";