经在这个论坛上看到一种说法,在A页面中设置的session值,如果从A页面链接到B页面,而B页面是个frameset,并且保存成htm格式,则该frameset底下的jsp页面读这个session的时候会读取不到session的值我现在就是这个情况!!!
但我转到的是index.jsp,是jsp啊!!!这是index.jsp的代码
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=GB2312" %>
<%@ include file="logchk.jsp" %>
<html>
<head>
<title>Orioxi Common System for Production Group</title></head><frameset name="mainframeset" frameborder="0" framespacing="0" border="0" cols="*" rows="75,*">
  <frame marginwidth="0" marginheight="0" src="heading.jsp" name="heading" noresize scrolling="no">
  <frameset name="framesetname" frameborder="0" framespacing="0" border="0" cols="180,10,*" rows="*" FRAMEBORDER="no">
    <frameset frameborder="0" framespacing="0" border="0" cols="*" rows="0,*">
      <frame marginwidth="0" marginheight="0" src="tree.jsp" name="code" noresize="yes" scrolling="no" frameborder="0">
      <frame marginwidth="5" marginheight="5" src="menu_empty.html" name="menu" noresize="yes" scrolling="auto" frameborder="0">
    </frameset>
    <frame marginwidth="0" marginheight="0" name="middle" src="middle.htm" SCROLLING="no" NORESIZE="yes">
    <frame marginwidth="0" marginheight="0" name="text" src="main.html" noresize="yes" CROLLING="no">
  </frameset>
<noframes>
<p>The <code>NOFRAMES</code> element is to be used to give useful content to people with browsers that cannot display frames.  One example is Lynx, a text-based browser.</p>
</noframes>
/</frameset></html>

解决方案 »

  1.   

    而且我在这2个jsp分别打印session的id(session.getId())
    发现是不一样的!!!
      

  2.   

    对了
    如果我直接response.sendRedirect("tree.jsp");
    倒是可以拿到这个类的
      

  3.   

    关键我发现在login.jsp 和 tree.jsp
    的session的id居然不一样!贴一下login.jsp的关键代码:
    <%@ page language="java" import="java.sql.*,com.orioxi.common.system.*,java.lang.*" contentType="text/html; charset=GB2312" %>
    <jsp:useBean id="myUsers" scope="application" class="com.orioxi.common.system.Users"/>
    <jsp:useBean id="mySession" scope="session" class="com.orioxi.common.util.SessionControl" />
    <%
    String LoginName=request.getParameter("LoginName");
    String Password=request.getParameter("Password");
            boolean chkUser = myUsers.isUser(LoginName);        if (chkUser = true){
            UsersInfo loguser = myUsers.getUser(LoginName) ;         if (LoginName!=null)
             {
     boolean chkLogin = false;
     if (loguser.Password.toString().equals(Password.trim())){
        chkLogin = true;
     }
                     if (chkLogin)
    {
                       mySession.UserID = loguser.UserID ;
                       mySession.LoginName = loguser.LoginName ;
                       mySession.RealNameCN = loguser.RealNameCN ;
                       mySession.RealNameEN = loguser.RealNameEN ;
                       mySession.Privilege = loguser.Privilege ;
                       mySession.Language = loguser.Language ;
                       mySession.authenticate = "1";
    request.getSession(true);   
    session.setAttribute("xxx", (com.orioxi.common.util.SessionControl)mySession); 
    response.sendRedirect("index.jsp");
    %>
    略tree.jsp:
    <%@ page language="java" import="java.sql.*,com.orioxi.common.util.*"  contentType="text/html;charset=gb2312" %>
    <jsp:useBean id="myTree" scope="page" class="com.orioxi.common.util.TreeMenu" />
    <jsp:useBean id="myDoText" scope="page" class="com.orioxi.common.util.DoText" />
    <jsp:useBean id="mySession" scope="session" class="com.orioxi.common.util.SessionControl" />
    <%
    mySession = (SessionControl)session.getAttribute("xxx"); 
    String LoginName = mySession.LoginName; //(String) session.getValue(session.getId());
    String RealNameCN =mySession.RealNameCN; //(String) session.getValue(session.getId());
    String RealNameEN =mySession.RealNameEN; //(String) session.getValue(session.getId());
    String Language =mySession.Language; //(String) session.getValue(session.getId());
    String Privilege = mySession.Privilege;
    String authenticate =mySession.authenticate; //(String) session.getValue(session.getId());
      

  4.   

    怀疑和客户端的cookie有关
    试试这句话:
    response.sendRedirect(response.encodeURL("index.jsp"));
      

  5.   

    sessionid默认是通过cookie来保存的,而cookie是只有向浏览器输出之后才会保存到客户端.
    因此如果你在第一次调用session后直接sendredirect,cookie是不会被浏览器所处理的,所以你的目标url就得不到sessionid而重新建立了一个session,你上面对session的赋值也当然无效了.
      

  6.   

    回  coaa(我吃多了) 
    不行唉
    haichuang(不戒和尚) 
    看的不是明白,请问具体该怎么改?
    用<jsp:forward>我也不行啊谢谢
      

  7.   

    先改成response.sendRedirect(response.encodeURL("index.jsp"));
    后再把index.jsp里面:
    <frame marginwidth="0" marginheight="0" src="tree.jsp" name="code" noresize="yes" scrolling="no" frameborder="0">src="tree.jsp"也改成src="<%=response.encodeURL("tree.jsp")%>"
    试一下呢?
      

  8.   

    而且我在这2个jsp分别打印session的id(session.getId())
    发现是不一样的!!!关键在这里啊   :(
      

  9.   

    知道啊,所以我才用response.encodeURL的.
    index.jsp和login.jsp里面session id是一样的吗?我自己机器上简单试过了,没有这个问题了.....
      

  10.   

    试试改成<%=request.getContextPath()%>/你的tree.jsp的完整路径
    sendRedirect里面也是
      

  11.   

    index.jsp和login.jsp里面session id不一样现在我又试了下
    发现如果redirect直接给tree.jsp的话,这样session的id就一致了!!!
    给index.jsp就会有问题
    我在想,是不是index.jsp里的frame太多了???
      

  12.   


    我把
    <frame marginwidth="0" marginheight="0" src="heading.jsp" name="heading" noresize scrolling="no">
    里的heading.jsp改成.htm文件
    居然就好了??!!
      

  13.   

    晕.......
    index.jsp和login.jsp里面session id不一样了,在tree.jsp还是对的.
    迷惑中.........
    不知道那位能给个解释.
      

  14.   

    呵呵
    我也很迷惑
    我花了一整天的时间来摸索,才发现把heading.jsp改成.htm文件就可以了
    我只听说把htm改成jsp的,还没听说过反过来改的
    难不成heading.jsp吃了那个session???
    而且你只要把和head.jsp和tree.jsp那2个frame的位置换一下,就又正常了 - -!
    明天来节帖
    再次感谢 coaa(我吃多了) 等回复的朋友