String login=request.getParameter("login");
String pass=request.getParameter("pass");
VIP v=new VIPServer().Login(login);
if(v==null)
{
out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>");
return;
}
if(!v.getPass().equals(pass))
{
out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>");
return;
}
session.setAttribute("vip",v);
out.print("<script>location.replace('../index.jsp');</script>");
return;
这是登陆代码

解决方案 »

  1.   

    <s:property value="#session.vip"/><s:if test="#session.vip">
      

  2.   

    <s:if test='session.vip==null'>   楼主这样试试
      

  3.   

    <s:if test="%{#session.vip==null}">
    除了<s:property/>外,一般标签是不认OGNL表达式的,必须加上%转换,不然会当成普通的字符串处理。
      

  4.   

    你是把这个vip的字段放在session里面吗?   如果是 那就直接<s:if test='vip==null'>
      

  5.   


    VIP是个类,里面存储了读取的所有字段,我试了你的方法还是不行,java怎么这么难搞,一个问题耗了我大半天
      

  6.   


    VIP是个类,里面存储了读取的所有字段,我试了你的方法还是不行,java怎么这么难搞,一个问题耗了我大半天'vip==null' 这个是想干嘛?
    判断所有字段是不是为空?
      

  7.   


    VIP是个类,里面存储了读取的所有字段,我试了你的方法还是不行,java怎么这么难搞,一个问题耗了我大半天'vip==null' 这个是想干嘛?
    判断所有字段是不是为空?想判断session是否为null,为null显示登陆,否则显示会员信息
      

  8.   

    <s:if test="${sessionScope.vip==null}"/>
    试试
      

  9.   

    <s:if test="${sessionScope.vip==null}">
     <
    </s:if>
      

  10.   

    能给我看下你的session吗  就是 session.setAttribute这个session从哪来的
      

  11.   

    下面这个是登陆验证的
    String login=request.getParameter("login");
    String pass=request.getParameter("pass");
    VIP v=new VIPServer().Login(login);
    if(v==null)
    {
    out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>");
    return;
    }
    if(!v.getPass().equals(pass))
    {
    out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>");
    return;
    }
    session.setAttribute("vip",v);
    out.print("<script>location.replace('../index.jsp');</script>");
    return;下面这个是访问数据库的
    public VIP Login(String login)
    {

    try
    {
    con=this.getcon();
        String sql=String.format("select * from [VIP] where login='%s'",login);
    ps=con.prepareStatement(sql);
    rs=ps.executeQuery();
    if(rs.next())
    {
    VIP v=new VIP();
    v.setId(rs.getInt("id"));
    v.setXueli(rs.getString("XueLi"));
    v.setLogin(rs.getString("login"));
    v.setPass(rs.getString("pass"));
    v.setName(rs.getString("name"));
    v.setSex(rs.getString("sex"));
    v.setAge(rs.getInt("age"));
    v.setHobby(rs.getString("hobby"));
    v.setShuoShuo(rs.getString("shuoshuo"));
    v.setHeight(rs.getString("height"));
    v.setHun(rs.getString("hun"));
    v.setRegTime(rs.getDate("regTime"));
    v.setImg(rs.getString("img"));
    return v;
    }

    }catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    }finally{
    this.closeAll(con, ps, rs);
    }
    return null;
    }
      

  12.   

    下面这个是登陆验证的
    String login=request.getParameter("login");
    String pass=request.getParameter("pass");
    VIP v=new VIPServer().Login(login);
    if(v==null)
    {
    out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>");
    return;
    }
    if(!v.getPass().equals(pass))
    {
    out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>");
    return;
    }
    session.setAttribute("vip",v);
    out.print("<script>location.replace('../index.jsp');</script>");
    return;下面这个是访问数据库的
    public VIP Login(String login)
    {

    try
    {
    con=this.getcon();
        String sql=String.format("select * from [VIP] where login='%s'",login);
    ps=con.prepareStatement(sql);
    rs=ps.executeQuery();
    if(rs.next())
    {
    VIP v=new VIP();
    v.setId(rs.getInt("id"));
    v.setXueli(rs.getString("XueLi"));
    v.setLogin(rs.getString("login"));
    v.setPass(rs.getString("pass"));
    v.setName(rs.getString("name"));
    v.setSex(rs.getString("sex"));
    v.setAge(rs.getInt("age"));
    v.setHobby(rs.getString("hobby"));
    v.setShuoShuo(rs.getString("shuoshuo"));
    v.setHeight(rs.getString("height"));
    v.setHun(rs.getString("hun"));
    v.setRegTime(rs.getDate("regTime"));
    v.setImg(rs.getString("img"));
    return v;
    }

    }catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    }finally{
    this.closeAll(con, ps, rs);
    }
    return null;
    }我要看的是servlet整个  那个session是在哪定义的 懂不
      

  13.   

    这个打印出来吗?
    <s:property value="#session.vip"/>
    ${vip}
      

  14.   

    即使是空的,应该也不报错啊,已经判断是否为null了
      

  15.   

    session为null重null中取数据,一定会报错的哦。
      

  16.   

    很少用jsp, 但根据错误提示应该是编译有问题。检查一下是不是确少什么包。
      

  17.   


    没有取数据啊,session.vip==null,我没有从vip里面取任何数据啊
      

  18.   


    <% Mod.VIP v=(Mod.VIP)session.getAttribute("vip"); %>
    <%=v.getLogin() %>这样可以读出来