2017-05-31 102 views
0

我有以下代碼如何隱藏不相關的鏈接?

<body> 

<% 
    String loggedInUserName = (String) request.getAttribute("loggedInUserName"); 
%> 
<% 
    String userRole = "lead"; 
%> 
<% 
    if (loggedInUserName.equals(userRole)) { %>  
    <%@ include file="tabs.jsp"%> 

<a href="dataOwner-index.html" style="visibility: hidden"></a> 
<a href="dataOwner-riskAssessmentCompliance.html"style="visibility: hidden"></a> 
<a href="security_setup.html" style="visibility: hidden"></a> 
<% 
    } 
%> 

而tabs.jsp包含

<div class="tslcNav" role="navigation"> 
    <div class="navbar-collapse collapse"> 
     <ul class="nav navbar-nav"> 
      <li><a href="index.html">Home</a></li> 
      <li><a href="mngPost.html">Manage Portfolio</a></li> 
      <li><a href="riskAssesment.html">Risk Assesment</a></li> 
      <li><a href="securitySetup.html">Security Setup</a></li> 
      <li><a href="dataOwner-index.html">Home</a></li> 
      <li><a href="dataOwner-riskAssessmentCompliance.html">Assessment Workbook</a></li> 
      <li><a href="security_setup.html">Security Setup</a></li> 
     </ul> 
    </div> 
    <!--/.nav-collapse --> 
</div> 

哪些錯誤與此代碼?它顯示了所有tabs.I要顯示只有那些導致相關標籤我想隱藏其他鏈接,即標籤。

回答

0

它顯示所有的標籤,因爲你是包括整個tabs.jsp這一行

<%@ include文件= 「tabs.jsp」 %

而且你有後三條線只需在標籤後面添加三個帶隱藏樣式的新的<a>到生成的HTML頁面即可。

你需要解決這個問題,什麼是先刪除這些行

<a href="dataOwner-index.html" style="visibility: hidden"></a> 
<a href="dataOwner-riskAssessmentCompliance.html"style="visibility: hidden"></a> 
<a href="security_setup.html" style="visibility: hidden"></a> 

只適用隱藏僅在您不希望在tabs.jsp顯示標籤的樣式,你可以使用el做像這樣

<li><a href="index.html">Home</a></li> 
<li><a href="mngPost.html">Manage Portfolio</a></li> 
<li><a href="riskAssesment.html">Risk Assesment</a></li> 
<li><a href="securitySetup.html">Security Setup</a></li> 

<li><a href="dataOwner-index.html" ${ loggedInUserName eq userRole ? 'style="visibility: hidden"' : '' }>Home</a></li> 
<li><a href="dataOwner-riskAssessmentCompliance.html" ${ loggedInUserName eq userRole ? 'style="visibility: hidden"' : '' }>Assessment Workbook</a></li> 
<li><a href="security_setup.html" ${ loggedInUserName eq userRole ? 'style="visibility: hidden"' : '' }>Security Setup</a></li>