• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Variable problem in EJB

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I am getting problem when I run my J2EE application on JBOss 3.0.7.
The scenario is :-
While a user(client from jsp) requests Servlet to view the products-page, a session for ClientFacade (EJB file) is created in that servlet, so that for the next request to ClientFacade, it just uses the session variable. Here session variable nevigates between servlet and jsp.This session variable retains the value only for two times from jsp to servlet, and gets null.

I create seesion variable for each visitor to store its value of shopping cart.But here also the same problem, this session created value does not exist in session variable for more that two hits to servlet.

I found myself stucked in this point.
I would appreciate my friends for this help me .
Thanks in advance !!
[ October 13, 2004: Message edited by: Ramesh Kumar Swarnkar ]
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This session variable retains the value only for two times from jsp to servlet, and gets null.



Is the session getting timed out somewhere? :roll:
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I create seesion variable for each visitor to store its value of shopping cart.But here also the same problem, this session created value does not exist in session variable for more that two hits to servlet.



What is your condition for create session variable ?


In each user have different session's attribute or not ?
 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
Thanks a lot for so quick response.
I am writting the servlet which is requested by jsp to create session.

-----------------------------------------------------------
public class ControllerServlet extends HttpServlet
{
private StudentFacadeHome studentFacadeHome;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try {
Context ctx = new InitialContext();
studentFacadeHome = (StudentFacadeHome) ctx.lookup("day11/StudentFacade");
} catch (Exception e) { throw new ServletException(e.toString()); }
}
public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
HttpSession session = request.getSession(true);
String pageName = request.getParameter("pageName");
if ( pageName != null )
if ( pageName.equals("displayProducts" ))
{processDisplayProducts(request, response, session); }
else if ( pageName.equals("catalogPage" ))
{addToCart(request, response, session); }
else if ( pageName.equals("viewCart" ))
{retrieveCartItems(request, response, session); }


//$$$$$$$$$$$$$$$$$$$$$ DISPLAY PRODUCTS $$$$$$$$$$$$$$$$$$
void processDisplayProducts (HttpServletRequest request,
HttpServletResponse response,
HttpSession session ) throws ServletException, IOException
{
StudentFacade studentFacade = null;
try {
studentFacade = (StudentFacade) studentFacadeHome.create();
session.putValue("StudentFacade", studentFacade);
session.setAttribute("courseItemList", studentFacade.getCourseItemList());

forwardToPage(request, response, "/products.jsp");
} catch ( Exception e)
{ System.err.println(throw new ServletException(e.toString());}

}


//$$$$$$$$$$$$$$$$$$$$$ ADD TO SHOPPING CART $$$$$$$$$$$$$$$$$$
void addToCart(HttpServletRequest request,
HttpServletResponse response,
HttpSession session ) throws ServletException,Exception
{
try {
StudentFacade studentFacade = (StudentFacade)session.getValue("StudentFacade");
String itemId = request.getParameter("buy");
if ( itemId != null )
{
String visiId = (String)session.getValue("VISITOR");
int qnty = 1;
if(visiId==null)
{
visiId = generateVisiID();
session.putValue("VISITOR",visiId);
}
studentFacade.addOrder(visiId,itemId,qnty);
}
forwardToPage(request, response, "/products.jsp");
} catch ( Exception e) {throw new ServletException(e.toString());}
}


//$$$$$$$$$$$$$$$$$$$$$ RECEIVE THE SHOPPING CART ITEMS $$$$$$$$$$$$$$$

void retrieveCartItems (HttpServletRequest request,
HttpServletResponse response,
HttpSession session ) throws ServletException, IOException
{
---------------------
--------------------
}


private String generateVisiID()
{ return new Long(System.currentTimeMillis()).toString(); }
void forwardToPage(HttpServletRequest request,
HttpServletResponse response, String page)
throws ServletException, IOException
{
RequestDispatcher disp = this.getServletContext().getRequestDispatcher(page);
disp.forward(request, response);
}

}

-----------------------------------------------------------
Here when user selects the product(in jsp page) and requests the servlet file to add it to cart, it works till user purchases two items from jsp product-dispaly page.Third time when user clicks add to cart in jsp, it gets new session id for same user.

Same thing for session.getValue("StudentFacade") also. IT gets null after purchasing two items.
Hope it may help you to analyse the scenario well.......
[ October 13, 2004: Message edited by: Ramesh Kumar Swarnkar ]
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you get null value from another session's attribute ??

IF you can get null, i think , session will expired.
 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Somkiat Puisungnoen,
Well I have posted here my Code.
Where to look for session elongation ?
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can specify the timeout value in web.xml
http://e-docs.bea.com/wls/docs61/webapp/web_xml.html#1017356

Avoid using session.putValue and getValue as they are deprecated.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why you use session.setAtribute() and session.putValue() ?

My suggestion, please change session.putValue() to session.setAttribute().
 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Somkiat puisungnoen & Pradeep Bhat

....After changing the putValue and getValue for Session into setAttribute and getAttribute, I am able to add three items to shoppong cart.If I continue in the same browser from beggining, then I can add four itmes to cart......!!
I dont why it is happenig..!!
Puuzled.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
putValue
public void putValue(java.lang.String name,
java.lang.Object value)Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
Parameters:
name - the name to which the object is bound; cannot be null
value - the object to be bound; cannot be null
Throws:
IllegalStateException - if this method is called on an invalidated session
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getValue
public java.lang.Object getValue(java.lang.String name)Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String).
Parameters:
name - a string specifying the name of the object
Returns:
the object with the specified name
Throws:
IllegalStateException - if this method is called on an invalidated session
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ramesh Kumar Swarnkar:
Hi Somkiat puisungnoen & Pradeep Bhat

....After changing the putValue and getValue for Session into setAttribute and getAttribute, I am able to add three items to shoppong cart.If I continue in the same browser from beggining, then I can add four itmes to cart......!!
I dont why it is happenig..!!
Puuzled.



From the begining? Do you mean you are using the Back button and going to the first page ?
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ramesh Kumar Swarnkar:
Hi Somkiat puisungnoen & Pradeep Bhat

....After changing the putValue and getValue for Session into setAttribute and getAttribute, I am able to add three items to shoppong cart.If I continue in the same browser from beggining, then I can add four itmes to cart......!!
I dont why it is happenig..!!
Puuzled.



In your system should be created signon process for each user.

I think, your app use same session's attribute to keep shopping cart.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic