你可以调用session.getAttribute("username")方法得到吗。

解决方案 »

  1.   

    username=session.getAttribute("username");//
      

  2.   

    或在index.jsp加入一行代码
    <%
          System.out.println(session.getAttribute("username"));
    %>
      

  3.   

    少写一句
    String username = request.getParameter("username") ;如果没有成功登录的话不会返回首页
    取得session属性 session.getAttribute("username");
    session为容器对象 与登录用户无关
      

  4.   

    <%
    String username = request.getParameter("username") ;
      %>
    我这样得到
    <%=username%>
    这样显示是NULL的结果
    <%=session.getAttribute("username")%>
    这样显示是username的结果这里的username不是用户名就是字符串"username"
      

  5.   

    你可以在成功登陆的时候:将用户名放进session 
      

  6.   

    session.setAttribute("username",username);//这里是得到session我这样就是想在成功登陆的时候:将用户名放进session 不知道这样写对不对阿
      

  7.   

    response.sendRedirect("index.jsp?page=1");
    Redirect重定向
    消毁request对象
      

  8.   

    说得我不是很明白阿Redirect重定向
    消毁request对象
    何session有什么关系?
      

  9.   

    能不能明确说一下那个代码到底能不能得到session如果不能应该怎么写才能得到
    谢谢
      

  10.   

    login.jsp
    <%
    String name = request.getParameter("name");
    String passsword = request.getParameter("password");
    if(name.equals("tomuno")&&password.equals("csdn"))
    {
    session.setAttribute("name",name);
    response.sendRedirect("success.jsp");
    }
    else{
    response.sendRedirect("login.jsp");
    }
    %>success.jsp
    who am i:
    <%=session.getAttribute("name")%>
      

  11.   

    我运行你的程序
    if(name.equals("tomuno") && password.equals("csdn"))这里报错阿不过我看应该没错阿
    c:\jakarta-tomcat-4.0\work\localhost\_\_0002fsducn_0005fshop_0002ftest_0002flogin_0002ejsplogin_jsp_0.java:59: Undefined variable or class name: password
                    if(name.equals("tomuno") && password.equals("csdn"))
                                                ^
    错误就是这个
      

  12.   

    1.request.getSession() will return a session whether the session exists or not2.so in common, we always set some Object into session, and if the object not here then you can know the one must be the first time here!3.common usage is request.getAttribute() not request.getParameter()!
      

  13.   

    String username=(String)session.getAttribute("username");//
    if (username != null){
    session已经获得
    }
      

  14.   

    说来说去没一个正确答案
    还是 tomuno(tomuno) 老兄的好
    虽然有问题不过他总归明白我的意思
      

  15.   

    String passsword = request.getParameter("password");
    password not passsword