日期:2014-05-17  浏览次数:20617 次

刚学到Session,遇到一点小问题求解释!!
我想用Session实现购物车,问题出现在下面的链接上:
<a href='"+request.getContextPath()+"/servlet/BuySession?name="+s+"'>结账</a>这个链接没有问题,但是这样写就出现了问题:
<a href='http://localhost:8080/"+request.getContextPath()+"/servlet/BuySession?name="+s+"'>购买</a>加了http://localhost之后,发现别的Servlet取不到Session对象了,浏览器没有关闭。
难道是加了http;//localhost之后就等同于重新开一个浏览器啊?

------解决方案--------------------
<a href='http://localhost:8080/"+request.getContextPath()+"/servlet/BuySessionname="+s+"'> 路径问题,request.getContextPath()获取的值前面已经是“/”+“你的项目名称“
改成
<a href='http://localhost:8080"+request.getContextPath()+"/servlet/BuySession?name="+s+"'>