是不是 URL 重写的问题?

解决方案 »

  1.   

    login.htm<form method="post" action="Hand_Login.jsp"><table width="290"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td>&nbsp;</td>
            <td><img src="images/user.gif" width="82" height="13"></td>
            <td><input class="input1" type="text" name="user_name" value="admin"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><img src="images/passwordd.gif" width="82" height="13"></td>
            <td><input  class="input2"type="password" name="password" value="123456"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td><table width="100%"  border="0" cellspacing="3" cellpadding="0">
              <tr>
                <td width="56%">&nbsp;</td>
                <td width="44%"><input name="imageField" type="image" src="images/bttouu.gif"value="submit" width="46" height="18" border="0"></td>
              </tr>
            </table></td>
          </tr>
        </table>
        </form>hand_login.jsp<%
    Share_Connection conn = null;  //建立连接
      conn = Connection_Factory.Get_Bean_Share_Connection();
      if(conn == null)
      {
        throw new Exception("得到数据库连接错误。。");
      }   String User_Name = request.getParameter("user_name");
       String Password = request.getParameter("password");   Logon_Checker The_Logon_Checker = new Logon_Checker();   //SafeWord验证
       Checker A_Checker = new SafeWord_Checker(conn);
       The_Logon_Checker.Register(A_Checker);   //登录限制
       A_Checker = new Restrict_Checker(request,conn);
       The_Logon_Checker.Register(A_Checker);   User The_User = The_Logon_Checker.Check_User(User_Name,Password);
       if(The_User == null)
       {
         throw new Exception(The_Logon_Checker.Get_Error_Msg());
       }
     
       The_User.Init_User_Info(session,conn);
       if(conn != null)
      {
        conn.Real_Close();
      }
       session.setAttribute("User",The_User);/*User abc = (User)session.getAttribute("User");
       out.print(abc.Get_User_Name());//在这里能取到session中的值
       if (abc == null)
       {
          Gmcc_Exception e = new Gmcc_Exception("您还没有登陆!");
         throw e;
       }*/
    response.sendRedirect("http://localhost:9080/app/index.jsp"); 
    %>index.jsp
    <%@ page import=" authentication.User" %>
    <%@ page errorPage="login.jsp" %>
    <%
       User The_User = (User)session.getAttribute("User");//到这里就取值为null了
       if (The_User == null)
       {
          Gmcc_Exception gmcc_e = new Gmcc_Exception("您还没有登陆!");
         throw gmcc_e;
       }
    %>
    login.jsp
    <%@ page isErrorPage = "true" %>
    <form method="post" action="Hand_Login.jsp"><table width="290"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td>&nbsp;</td>
            <td><img src="images/user.gif" width="82" height="13"></td>
            <td><input class="input1" type="text" name="user_name" value="admin"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><img src="images/passwordd.gif" width="82" height="13"></td>
            <td><input  class="input2"type="password" name="password" value="123456"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td><table width="100%"  border="0" cellspacing="3" cellpadding="0">
              <tr>
                <td width="56%">&nbsp;</td>
                <td width="44%"><input name="imageField" type="image" src="images/bttouu.gif" width="46" height="18" border="0"></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td colspan="2" align="center"><%= exception.getMessage() %></td>
          </tr>
        </table>
        </form>
    为了方便大家看看,我把不必要的东东去掉了。
      

  2.   

    URL重写的问题?我不太明白。King6860() 能详细说说吗?
      

  3.   

    response.sendRedirect("http://localhost:9080/app/index.jsp"); 
    把这句话的地址该为相对地址
    response.sendRedirect("./app/index.jsp");
      

  4.   

    问题好像是这样的
    由Login.htm->hand_login.jsp->index.jsp,无法在session里取得User
    由Login.jsp->hand_login.jsp->index.jsp,可以在session里取得User
    应该和跳转无关的不过在我的机器上没有出现这个问题啊
      

  5.   

    leafcoco,你登陆操作的几个类我没有,所以没法进行完整的调试。建议你在hand_login.jsp页面里的开始和结尾部分检查一下输入的参数和得到的结果(User),确认一下最终session里有没有User对象,耐心点调试吧。//加油
      

  6.   

    我简直要绝望了,5555555555555。
    在hand_login.jsp页面检查过了,能得到东西,可到index.jsp就没了
      

  7.   

    我觉得问题不出在你贴出来的那些代码里面,而在你的user类里面。
    可以用以下方法先校验以下:
    1. hand_login.jsp以下代码:
       User abc = (User)session.getAttribute("User");
       out.print(abc.Get_User_Name());
       改为:
       out.print(session.getAttribute("User")); 
    2. index.jsp以下代码:
       User The_User = (User)session.getAttribute("User");//到这里就取值为null了
       改为:
       out.print(session.getAttribute("User")); 如果现在index.jsp能取到session的值(我相信应该是这种情况),那就肯定可以说明是你的user类里面有问题了。打印调试一下user类里面的方法一定能解决。