【问题标题】:Displaying HTML code based on condition JSP基于条件 JSP 显示 HTML 代码
【发布时间】:2018-11-29 02:00:17
【问题描述】:

我正在尝试根据使用 JSP 的数据可用性来显示 div。我的问题是,即使条件有效,并且负责显示 div 的相应块执行,我也无法查看在我的网页中呈现的上述部分。

<body>
     <form>
          <h3>Order Type</h3>
          <div id="orderType" class="specialOrder">
            <table>
                <tr><td><label id="numberLabelId" for="numberId">Number</label>
                     <input type="text" name="number" id="numberId" onchange="processInput()"/>
                     <input type="hidden" name="groupSize" value="1" id="groupSizeId"/>
                </td></tr>
            </table>
          </div>
            <%
                boolean dataReceived = false;
                boolean isQualified = false;
                String qualificationMessage = "";
                String error = "";

                if(request.getParameter("json") != null)
                {
                    System.out.println("Response: " + request.getParameter("json"));

                    JSONObject jsonObject = JSONObject.fromObject(request.getParameter("json"));
                    MPQResponse mpqResponse = (MPQResponse) JSONObject.toBean(jsonObject, MPQResponse.class);

                    isQualified = mpqResponse.isQualified();
                    qualificationMessage = mpqResponse.isQualified() ? "Number is qulified for porting": "Number is not qualified for porting";
                    error = mpqResponse.getErrorMessage();
                    dataReceived = true;

                    System.out.println("Qualification status: " + qualificationMessage);
                    System.out.println("Error: " + error);
                }
            %>
            <%
                if(dataReceived && isQualified)
                {
            %>
                 <div><%=qualificationMessage%>/div>
                 <script type="text/javascript" >
                     refreshPage();
                 </script>
           <%
                }
                else
                {
           %>
                <div><%=qualificationMessage%></div>
                <div><%=error%></div>
            <%
                }
            %>
        </form>
</body>

以上是我的代码的一部分;在上面的部分中,即使dataReceivedisQualifiedtrue,此块中的div 部分也不会呈现(我可以看到代码使用调试器进入块)。我在拧什么?我试过 JTL &lt;c:if&gt; 还是一样的结果。

【问题讨论】:

    标签: java html jsp


    【解决方案1】:

    改变

    <div><%=qualificationMessage%>/div>
    

    <div><%=qualificationMessage%></div>
    

    close div 格式错误,缺少&lt; 符号

    【讨论】:

    • 感谢您的回复。我修好了,但仍然存在。另外我在div标签内尝试了静态文本,静态文本显示购买JSP表达式为空。
    • 可能和那个refreshPage有关。
    • 我也尝试删除refreshPage(),但没有成功。只是 JSP 表达式没有评估新值,即使我可以清楚地看到正在使用调试器评估该值
    猜你喜欢
    • 2015-12-11
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 2023-04-10
    • 2019-02-14
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多