在servlet中写入属性Login;并调用main.jsp
String temp1 = "OK";
session.setAttribute("Login", temp);
ServletContext tst = getServletContext().getContext("/webapp");
RequestDispatcher dispatcher = tst.getRequestDispatcher("/main.jsp");
dispatcher.forward(request, response);在main.jsp中获取Login却是null
String Login = (String)session.getAttribute("Login");如果在servlet和jsp中把session修改为request, 是可以正常传递的;为什么用session传递反而不行呢.非常着急,请大家帮忙看看,多谢了!!

解决方案 »

  1.   

    我在servlet和jsp中将sessionid输出,是一致的,说明session应该没有改变。 我是从jbuilder调试运行的servlet,跟这个有关系吗?
      

  2.   

    用request.getSession().setAttribute(); 试试。然后页面用  request.getSession().getAttribute(); 
      

  3.   

    Dragon_sxw, 试过这种方法不行。
    只有
    request.setAttribute(); 
    request.getAttribute(); 
    可以传过去
      

  4.   

    String temp1 = "OK"; 
    session.setAttribute("Login", temp); 你确定session中存放temp而不是temp1?
      

  5.   

    不好意思,刚才我简化程序的时候改错了,我设置的是temp1, 
    String temp1 = "OK"; 
    session.setAttribute("Login", temp1); 因为改成request就可以传递,所以我存储值的过程应该是没问题的。
    我没有打成war包,跟这个有关系吗?
      

  6.   

    session.setAttribute("Login", temp); 
    下面打印
    session.getAttribute("Login")
    能取么?
    和WAR包没关系
      

  7.   

    可以取到的我部署的时候是用的内嵌的jetty,
     Context context = new Context(contexts, "/", Context.SESSIONS);
    context.addServlet(
                        "com.gwtt.management.report.servlets.LoginServlet",
                        "/report/login");
     WebAppContext webapp = new WebAppContext(contexts, "web", "/webapp");
    跟我的部署有关吗?