Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB session vs web HttpSession  RSS feed

 
K. Tsang
Bartender
Posts: 3633
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers, correct me if I'm wrong about the mentioned sessions. They can't communicate with each other.

In servlets/JSP, I can always use EntityManager.find() or through EntityManager.createQuery() or the like to get the session bean and ultimately the database entity class.

Now if I use request.sendRedirect("somepage.jsp"), how do I possibly get the primary key for the EntityManager methods? I can't use request.getParameter("fieldname").

I'm thinking can I do this: in servlets do what needed with those getter methods and use HttpSession to setAttribute, eg:

Then in JSP use String key = (String) session.getAttribute("key"); or Abc abc = (Abc) session.getAttribute("abc");

But then this would mean using the regular session in the web container to propagate data. Can I not use HttpSession at all? What's the proper approach?

Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36463
462
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K. Tsang:
Hi ranchers, correct me if I'm wrong about the mentioned sessions. They can't communicate with each other.

That is correct.


Then in JSP use String key = (String) session.getAttribute("key"); or Abc abc = (Abc) session.getAttribute("abc");

But then this would mean using the regular session in the web container to propagate data. Can I not use HttpSession at all? What's the proper approach?

This approach is correct. What do you mean by the "regular session" ? It is an HttpSession.
 
K. Tsang
Bartender
Posts: 3633
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:

This approach is correct. What do you mean by the "regular session" ? It is an HttpSession.


Yes I mean HttpSession when I say regular session in the web container.

Better yet how to turn entity class to JavaBean so that in JSP I can use <jsp:useBean class=""bla" id="abc" scope="session" /> tags then use abc.getXXX() to get the entity class's data?
[ June 03, 2008: Message edited by: K. Tsang ]
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36463
462
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K. Tsang:
Better yet how to turn entity class to JavaBean so that in JSP I can use <jsp:useBean class=""bla" id="abc" scope="session" /> tags then use abc.getXXX() to get the entity class's data?

A JPA entity IS already a JavaBean. You can disconnect from the database by calling detach(). Which would allow you to put in the request/session.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!