java 将if-else与html一起使用时出现jsp错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1231228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:44:46 来源:igfitidea点击:
jsp error when using if-else with html
提问by vehomzzz
I have the following in my jsp page (assume that client is an object )
我的jsp页面中有以下内容(假设客户端是一个对象)
<%
if( client == null)
%>
NO client
<%
else
%>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
thanks
谢谢
回答by ChssPly76
You're missing the brackets:
你缺少括号:
<% if( client == null) { %>
NO client
<% } else { %>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
<% } %>
That said, this is an example of bad JSP code. Consider using JSTL tags / expressions instead of scriptlets.
也就是说,这是一个糟糕的 JSP 代码示例。考虑使用 JSTL 标记/表达式而不是 scriptlet。
回答by Peter
in jstl it would be something similar to
在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>

