前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >session.setAttribute报错_java string contains方法

session.setAttribute报错_java string contains方法

作者头像
全栈程序员站长
发布2022-11-08 11:29:13
3100
发布2022-11-08 11:29:13
举报
文章被收录于专栏:全栈程序员必看

HTTPSession在setAttribute时,保存的对象是否需要序列化?

查看StandardSession源码中,在setAttribute()中有如下代码

代码语言:javascript
复制
 if ((manager != null) && manager.getDistributable() &&
          !isAttributeDistributable(name, value))
            throw new IllegalArgumentException
                (sm.getString("standardSession.setAttribute.iae", name));

 protected boolean isAttributeDistributable(String name, Object value) {
        return value instanceof Serializable;
 }

 manager接口:
	
    /**
     * Return the distributable flag for the sessions supported by
     * this Manager.
     */
    public boolean getDistributable();
	
    /**
     * Set the distributable flag for the sessions supported by this
     * Manager.  If this flag is set, all user data objects added to
     * sessions associated with this manager must implement Serializable.
     *
     * @param distributable The new distributable flag
     */
    public void setDistributable(boolean distributable);

在web.xml配置<distributable/>后, manager中的distributable变量为true,在setAttribute时会检查对象是否序列化。

因此,session中的对象需不需要实现序列化,取决于是否支持分布式session。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/184136.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年10月9日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档