你好我是新的jsp我想检查jsp中的条件.值是否为空.?我在jsp页面中编写了以下代码
<% String s = request.getParameter("search"); %>
<%=s %>
<% if (<%=s ==null) { %>
<div>textbox is empty</div>
<% } else { %>
<div>textbox value..
<% } %>
Run Code Online (Sandbox Code Playgroud)
如果textbox值为null,我在变量中获取文本框值,然后它应显示第一个消息othervise second.告诉我该怎么办?
最好的方法是使用JSTL.请避免使用JSP中的scriptlet.
<c:choose>
<c:when test="${empty search}">
<div>textbox is empty</div>
</c:when>
<c:otherwise>
<div>textbox value is ${search}</div>
</c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)
<% String s = request.getParameter("search"); %>
<%=s %>
<% if (s==null || s.isEmpty()) { %>
<div>textbox is empty</div>
<% } else { %>
<div>textbox value..
<% } %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39475 次 |
| 最近记录: |