我有一个Jsp页面,每次打开该页面时都会加载警报框。我需要仅在满足某些条件时才显示此警报。这是我的JSP。每次页面加载时,这将加载一个空警报。
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <LINK REL="StyleSheet" HREF="css/style.css"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <form class ="menuOption" action ="MenuServlet" method ="GET"> <table border="0" class ="menuOption"> <tbody> <tr> <td>Enter Menu Option<input type="text" name="menuoption" value="" /><input type="submit" value="GO" name="gomenu" /></td> </tr> <tr> <c: if test="${not empty nulloption}"> <script>alert("${nulloption}");</script> </c:if> <c:if test="${not empty invalidMenu}"> <script>alert("${invalidMenu}");</script> </c:if> <td></td> <td></td> <td></td> </tr> </tbody> </table> </form> </body> </html>
尝试此操作以验证invalidMenu内容。
invalidMenu
<tr> <td><%= request.getAttribute("invalidMenu") %></td> <c:if test="${not empty invalidMenu}"> <script>alert("${invalidMenu}");</script> </c:if> <td></td> <% request.setAttribute("invalidMenu", "invalid menu name"); %> <c:if test="${not empty invalidMenu}"> <script>alert("${invalidMenu}");</script> </c:if> <td></td> </tr>