我在一个页面设置了SESSION,然后在该页显示该SESSION的值是存在的,然后用了response.sendRedirect("index.jsp");再在index.jsp页面显示该SESSION的值,却发现变成NULL,不知道是怎么回事,是不是服务器的问题?该如何解决?

解决方案 »

  1.   

    在index.jsp怎么得session的??
    贴出部分代码大家帮你看看
      

  2.   

    out.println(session.getAttribute("key"));就是这样显示
      

  3.   

    session的时间,不过在这里估计不是这个原因,
      

  4.   

    代码问题,是否确认set session之后才response.sendRedirect("index.jsp");的,session保存了吗
      

  5.   

    java是区分大小写的,你是不是把键值写错了
    也就是你的key,
      

  6.   

    我把代码贴出来,大家帮我看看
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.sql.*" errorPage="" %><%
    String uname=new String(request.getParameter("username").getBytes("ISO8859_1"),"GBK");String pword=new String(request.getParameter("password").getBytes("ISO8859_1"),"GBK");try
    {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      
      Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=21fgd","sa","");
      Statement stmt=con.createStatement();
      ResultSet rst=stmt.executeQuery("select count(*) from admin where username='"+uname+"' and password='"+pword+"'");
      int count=0;
      if(rst.next())
      {
         count=rst.getInt(1);
      }
      
      if(count!=1)
      {
          rst.close();
       stmt.close();
       con.close();
       response.sendRedirect("err_login.jsp");
      }
     
       session.setAttribute("key","true");    
          
       rst.close();
       stmt.close();
       con.close();  response.sendRedirect("index.jsp");

    catch(Exception e)
      {
        out.println(e);
      } 
    %>
    --------------------------------
    index.jsp里我就弄了一句<%
    out.println(session.getAttribute("key"));
    %>
    显示是NULL
      

  7.   

    还有,这个程序在我自己的电脑上是可以成功运行的,但是放到服务器上从网络访问就出现了SESSION变成NULL的问题了
      

  8.   

    晕死,原来是域名解析的问题,看了下页面源文件,<html>
    <head><title></title></head>
    <frameset cols='*' rows='*, 0'>
    <frame src='http://服务器IP地址' frameborder='0' scrolling='Auto' noresize marginwidth='0' marginheight='0'>
    </frameset>
    <!--
    <noframes><body>Frame required.</body></noframes>
    -->
    </html>
    每次页面变换后那个服务器IP地址都是一样的相当于重开了另一个页面导致SESSION失效
    这个是不是服务商没弄好的缘故?现在我的标题也无法正常显示了
      

  9.   

    你用的是转URL方式,并隐藏了真实URL,所以......