i try to create a servlet that set a session attribute called "cart" and use cookie to store the cart size(number of products from cart).
...then i am redirecting(using sendRedirect method) the servlet response to another jsp page(cart.jsp).
ok..cart.jsp display the cookie's value,except other previous 2 page..just when i refresh these pages,it gives the cookie's value.
Its not at all recommended to store persistent data in Cookies as we must design our applications in such a way that even if we do not get value from cookie, app must be able to function. You are better off creating an object that stores all cart related info and storing it as a session attribute(which you can manipulate in your cart.jsp page).Hope this helps...
What Hasha said is true, isn't recommended that you count on Cookies to develop a feature for your software, they may not work in some browsers and i suppose that you want your application runs properly in every kind of enviroments, right? Think on the cookies as a device to improve your features while caching something in the client of your user (like you know him, got it? .. you can say: "hey man .. i know you .. you've been here before john doe, how are you?" to make him more confortable )
About what you're trying to do, if you're trying to pass a value to a jsp and you're not gonna use this anymore we recommend that you use request scope instead, control values/attributes across scopes can become a nightmare. But to you do that in this scenario you've described, you'll need to replace the sendRedirect for HttpServletRequest.getRequestDispatcher("cart.jsp").forward(HttpServletRequest, HttpServletResponse), because the sendRedirect sends to the client a code 301 with the link specified as argument to the method in a header and who does the request is the browser, if you use the RequestDispatcher you'll do this at runtime and your user will not even know that the place he is right now isnt the place he requested.
Hope this helps, if it don't or if you have some other doubt, feel free to ask me .. i'll be pleased to help you!
Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6