2014-07-02 38 views
0

我想從這個代碼中刪除scriptlet和 我有Struts標籤來取代它,可以在任何一個建議我該怎麼辦呢Struts標籤,而不是JSP表達式標記(<%表達式%>)

 <td CLASS="PSEDITBOX_DISPONLY" align="left" colspan="5"> 
     +Name: <%=(user == null || user.getPreferredName() == null) ? "" : 
     user.getPreferredName()%> 
     </td> 
+0

移動代碼在服務器上,使用Struts標籤。這將使您的代碼緊湊,分離,可測試,易於理解。 –

+0

您可以在S2''標記中使用該表達式。 –

回答

0

使用<logic:present/>標記。

<td CLASS="PSEDITBOX_DISPONLY" align="left" colspan="5"> 
    +Name: 

    <logic:present name="user"> 
     < bean:write name="user" property="preferredName"/> 
    </logic:present> 

    <logic:notPresent name="user"> 
     --- (no preferred name)  
    </logic:notPresent> 
</td> 
+0

你能不能詳細地爲上面的代碼編寫代碼 – navi1401

+0

它不起作用。 – navi1401

+0

這是struts1。 –

0

定義與獲取方法的屬性在動作類

public String getPreferredName() { return (user == null || user.getPreferredName() == null) ? "" : user.getPreferredName() ;} 

更改代碼

<td CLASS="PSEDITBOX_DISPONLY" align="left" colspan="5"> 
    +Name: <s:property value="preferredName"/> 
</td> 
0

這個這個正確的格式,

<td CLASS="PSEDITBOX_DISPONLY" align="left" colspan="5"> 
    <s:if test="%{#user ==null } ||%{#user.preferredName ==null}"> 
     Name : 
    </s:if> 
    <s:else> 
     Name :<s:property value="preferredName"/> 
    </s:else> 
</td>