MyDes myDes1 = new MyDes();//加密类 WebContext ctx = WebContextFactory.get();//此方法官方不提倡用了 ctx.getHttpServletRequest() ; ctx.getSession().setAttribute("user", user); ctx.getSession().setAttribute("userName", myDes1.getCoookieString(user.getUsername()));//对用户名进行加密保存 ctx.getSession().removeAttribute("error");