一尘不染

从页面加载JSP删除警报

jsp

我有一个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>

阅读 189

收藏
2020-06-10

共1个答案

一尘不染

尝试此操作以验证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>
2020-06-10