我想用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之后就等同于重新开一个浏览器啊?

解决方案 »

  1.   

    是找不到路径了,不是取不到session。
      

  2.   

    你可以试着打印下request.getContextPath()的值为什么
      

  3.   

    你可以试着打印下request.getContextPath()
      

  4.   

    没太明白你说的“别的Servlet”是什么意思?
      

  5.   

    其他的servlet,包括结账的servlet
      

  6.   

    'http://localhost:8080' 我只在HTML中才用
      

  7.   

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