redis session共享中的序列化问题

redis session共享中的序列化问题,第1张

概述今天在做session对象存入redis(set方法)时,碰到一个空指针异常,代码如下:public class CheckAccount extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{HttpSession session=request.getSession();AccountBean account=new AccountBean();String username=request.getParameter("username");String password=request.getParameter("password");account.setPassword(password);account.setUsername(username);if((username!=null)&&(username.trim().equals("jsp"))){if((password!=null)&&(password.trim().equals("1"))){session.setAttribute("account", account);SessionService.getInstance().SaveSession(session);//System.out.println(session.getId());String logon_suc="session.jsp";response.sendRedirect(logon_suc);return ;}}String logon_fail="fail.jsp";response.sendRedirect(logon_fail);return;}public void doPost (HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{doGet(request,response);}}属性如下所示:public class AccountBean {private static final long serialVersionUID = 1390366007623566261L;private String username="";private String password="";public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}输出jsp代码为:<body><%=request.getSession().getId()%><br/><% AccountBean account=(AccountBean)request.getSession().getAttribute("account");%>user name:<%=account.getUsername() %><br/>password:<%=account.getPassword() %><br/></body>出错原因:AccountBean 作为session的属性,因session继承Serializable,被持久化保存到redis中,所以作完属性的AccountBean也必须序列化才能被存入redis中。

今天在做session对象存入redis(set方法)时,碰到一个空指针异常,代码如下:

CheckAccount = AccountBean account==request.getParameter("username"=request.getParameter("password"((username!=)&&(username.trim().equals("Jsp"((password!=)&&(password.trim().equals("1""account"="session.Jsp"="fail.Jsp" }

属性如下所示:

serialVersionUID = 1390366007623566261L String username="" String password="" .username = .password =

输出Jsp代码为:

<%=request.getSession().getId()%>
<% AccountBean account=(AccountBean)request.getSession().getAttribute("account");%><%=account.getUsername() %>
<%=account.getPassword() %>

出错原因:作为session的属性,因session继承Serializable,被持久化保存到redis中,所以作完属性的

总结

以上是内存溢出为你收集整理的redis session共享中的序列化问题全部内容,希望文章能够帮你解决redis session共享中的序列化问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1169113.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存