【发布时间】:2010-11-16 21:41:11
【问题描述】:
我的jsp页面中有以下内容(假设客户端是一个对象)
<%
if( client == null)
%>
NO client
<%
else
%>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
谢谢
【问题讨论】:
我的jsp页面中有以下内容(假设客户端是一个对象)
<%
if( client == null)
%>
NO client
<%
else
%>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
谢谢
【问题讨论】:
在 jstl 中会类似于
<c:choose>
<c:when test="${client is null}">
NO client
</c:when>
<c:otherwise>
<A href="<c:url value="page.jsp" >
<c:param name="aid" value="${client.ID}" />
</c:url>"
> and his name is <c:out value="${client.name}"/>
</c:otherwise>
【讨论】:
您缺少括号:
<% if( client == null) { %>
NO client
<% } else { %>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
<% } %>
也就是说,这是一个糟糕的 JSP 代码示例。考虑使用 JSTL 标记/表达式而不是 scriptlet。
【讨论】: