JSP如果总是执行else语句

时间:2016-06-13 16:29:00

标签: html jsp

我正在建立一个学校项目的网站。我想在两个不同的场景中加载相同的页面:

  1. 当已登录用户想要查看其个人资料时
  2. 当页面显示其他用户的个人资料
  3. 所以我的页面profile.jsp带有if

    <% if(request.getAttribute("u")!=null){ %>
    
       ---logged user stuff HTML---
    
    <% } else{ %>
    
       ---user stuff HTML---
    
    <% } %>
    

    它始终执行else语句,并确保request.getAttribute("u")返回正确的值。

    This is when i access the logged user's profile so the first one is the logged user (jack in this case) and the second is request.getAttribute("u") and here it should be null

    The first one is the logged user, the second is request.getAttribute("u"), here is carl and it's right, but it doesn't what it should

1 个答案:

答案 0 :(得分:0)

试试这段代码

<% String msg2=(String)request.getAttribute("u");%>

        <% if ( (msg2==null || msg2.isEmpty()) ) { %> 
         // WHAT YOU ARE NOT LOGED IN             
        <% } else if(msg2!=null) { %>

         <% }  %>