Help coderanch get a
new server
by contributing to the fundraiser
  • 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 tracking

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pls go through foll code and help me out in session tracking..
This is a ShoppingCart.java file
package test;
import java.util.*;
public class ShoppingCart
{
Hashtable ht;
public ShoppingCart()
{
ht=new Hashtable();
}
public void add(String item)
{
ht.put("item",item);
System.out.println("from shoppincart.java file");
System.out.println(ht.get("item"));

}
public void remove(String item)
{
ht.remove(item);
}
public void getItem()
{
System.out.println(ht.get("item"));
Enumeration e=ht.keys();
System.out.println(e.hasMoreElements());
while(e.hasMoreElements())
{
String s=(String)e.nextElement();
System.out.println(ht.get(s)+"getitems value" );
}
}
}
Here in this below JSP file iam adding a string ravi
<jsp:useBean id="shoppingcart" scope="session" class="test.ShoppingCart" />
<%
HttpSession cartsession=request.getSession(true);
ShoppingCart cart=new ShoppingCart();
cartsession.putValue(cartsession.getId(),cart);
shoppingcart.add("ravi");
System.out.println("after calling add method");
%>
Here in another JSP iam coding to get the value from session.
try
{
HttpSession cartsession = request.getSession(true);
out.println("before entering");
ShoppingCart cart=(ShoppingCart)(cartsession.getValue(cartsession.getId()));
out.println("after entering");
cart.getItem();
out.println("from viewcart.jsp");
}
catch(Exception e){out.println(e.getMessage()+"\n"+"error");}
Iam getting a null value from this.
Can u pls help me in this..
Rgds
RaviVunnam.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic