问题: 我有一个这样的jsp页面
<form action="MyServlet" method="post" >
<input type="text" name="word1" >
<input type="text" name="word2" >
<input type="text" name="word3" >
<button type="submit" name="search">Submit</button>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>word1</th>
<th>word2</th>
<th>word3</th>
</tr>
</thead>
<tbody>
<c:forEach items="${words}" var="word">
<tr>
<td><c:out value="${word.word1}"/></td>
<td><c:out value="${word.word2}"/></td>
<td><c:out value="${word.word3}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
这个 MyServlet 类:
String word1 = request.getParameter("word1");
String word2 = request.getParameter("word2");
String word3 = request.getParameter("word3");
SearchClass searchClass = new SearchClass();
String search = request.getParameter("search");
if(search !=null) {
List<Words> words = searchClass.search(word1, word2, word3);
request.getSession().setAttribute("words", words);
response.sendRedirect("words.jsp");
}
当我点击“提交”时,搜索这 3 个单词,如果找到,则重定向到包含表单的同一页面。 但如果没有找到,我想显示模式对话框,告诉 --- 没有找到结果 --- 如何实现这样的对话框?
我尝试使用 Bootstrap 模式,但它需要数据目标!
最佳答案
您可以使用<c:choose>
女巫等于a switch statement
.
说明
检查是否 words
为空 test="${empty words}"
并打印您的消息,否则显示 table
与结果。
代码
<c:choose>
<c:when test="${empty words}">
<p>no results found</p>
</c:when>
<c:otherwise>
<table>
// ...
</table>
</c:otherwise>
</c:choose>
关于javascript - jsp如何在模态对话框中显示 “no results found”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45772927/