草庐IT

interactive-session

全部标签

java - 如何使用 RESTlet 在 RESTful Web 服务中强制执行 'sessions'?

我是RESTfulWeb服务和RESTlet的新手。我们只有构建基于servlet的Web应用程序(JBoss/Apache上的Servlet/JSP)的经验。现在,我们正在构建一个基于RESTlet的应用程序,其中服务器端API将由两种类型的客户端使用-使用浏览器的Web和通过桌面的基于swing的客户端。我的理解是,根据REST概念a)服务器无法维护session以提高可伸缩性和其他一些原因b)客户端的每个请求都应该是独立的现在,我真的很困惑如何实现这一目标。假设我们采用一个简单的购物车应用程序。Step1)Client发送认证请求,Server认证,Server响应OK。第2步)

java - hibernate 异常 : Could not obtain transaction-synchronized Session for current thread

我遇到错误:Exceptioninthread"main"org.hibernate.HibernateException:Couldnotobtaintransaction-synchronizedSessionforcurrentthread主要ppService.deleteProductPart(cPartId,productId);@Service("productPartService")@OverridepublicvoiddeleteProductPart(intcPartId,intproductId){productPartDao.deleteProductPart

java - HttpSession - 如何获取 session.setAttribute?

我正在以这种方式创建HttpSession容器:@SessionScoped@ManagedBean(name="userManager")publicclassUserManagerextendsTools{/*[privatevariables]*/...publicStringlogin(){/*[finduser]*/...FacesContextcontext=FacesContext.getCurrentInstance();session=(HttpSession)context.getExternalContext().getSession(true);session.

java - session 属性访问并转换为 int?

我在Servlet中使用以下命令将用户ID存储在Session中:HttpSessionsession=request.getSession();session.setAttribute("user",user.getId());现在,我想从另一个Servlet访问该用户ID:HttpSessionsession=request.getSession(false);intuserid=(int)session.getAttribute("user");//ThisisnotworkingORUseruser=newUser();user.setId(session.getAttribu

java - 为什么在 JAVA 中 session.invalidate() 之后 session 不为空?

我在开发JavaEEWEB应用程序时遇到了一个非常奇怪的问题。即使在使用session.invalidate();使HttpSession无效之后,我也没有得到sessionnull。有一种情况,在使session无效后,我有一个语句正在执行,如下所示。if(null!=session&&null!=session.getAttribute("loginToken")){//dosomething}我在这里没有得到空session,所以第二个条件将尝试执行。因此session不为空,所以我得到IllegalStateException-sessionisalreadyinvalidat

java - Spring:单例/ session 范围和并发

Springbean的单例/session作用域是否要求对其所有字段的访问必须同步?通过“synchronized”关键字或使用“java.util.concurrent”包中的一些类。例如,这段代码不是线程安全的吗?(从here复制/粘贴):@Component@SessionScopedpublicclassShoppingCart{privateListitems=newArrayList();publicListgetAllItems(){returnitems;}publicvoidaddItem(Productitem){items.add(item);}}

java - org.hibernate.LazyInitializationException : could not initialize proxy - no Session, encore un fois

Foo看起来有这个:@ManyToManyprivateSetfavouritedBy;当用户有这个时:@ManyToMany(mappedBy="favouritedBy")privateSetfavourites=newHashSet();publicSetgetFavourites(){returnfavourite;}fooService有这个,在打开session时通过事务方法访问延迟加载的集合:@Transactional(readOnly=true)publicSetgetFavourites(Useruser){user=dao.get(User.class,user.

java - Spring hibernate : Illegal attempt to associate a collection with two open sessions

我正在尝试更新MySqlDb中的记录。更新时抛出以下异常org.hibernate.HibernateException:Illegalattempttoassociateacollectionwithtwoopensessionsatorg.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)atorg.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdate

java - 干净的代码、无状态 session bean 和私有(private)状态

根据RobertC.Martin的干净代码,方法应该有一个小签名。最好的情况是完全没有参数的方法。相反,建议使用状态变量。这真的很有用。但是无状态sessionbean呢?这个名字有点令人困惑,因为SLSB可以有状态。您只需要进行内务处理,这样您就不会使用之前EJB调用的状态。回到干净的代码:我也喜欢在SLSB中使用实例变量。这工作正常,如果您足够小心,您不会遇到任何状态不一致的问题,因为状态在每次公共(public)方法调用时都会被覆盖。到目前为止一切顺利。但是,如果用过的bean返回到池中会怎样?它带着它的状态。根据状态的大小,这可能是真正的内存泄漏。JBoss对bean非常慷慨,

java - Hibernate Session#merge 在收到带有 ID 的实体时是否应该插入?

这似乎经常出现,但我用谷歌搜索无济于事。假设您有一个Hibernate实体User。您的数据库中有一个ID为1的User。您有两个线程在运行,A和B。它们执行以下操作:A获取用户1并关闭其SessionB获取用户1并删除它A更改用户1的字段A得到一个新的Session并合并的用户1我所有的测试都表明merge试图在数据库中找到用户1(显然不能),因此它插入了一个ID为2的新用户。另一方面,我的期望是Hibernate会发现被合并的用户不是新用户(因为它有一个ID)。它会尝试在数据库中找到用户,这会失败,因此它不会尝试插入或更新。理想情况下,它会抛出某种并发异常。请注意,我正在通过@Ve