根据条件生成<h1> </h1>

时间:2014-03-31 16:02:53

标签: jsp sip

如果SIP Servlet中收到的消息是低优先级消息,我想将标头h1分配为“已收到低优先级警报”。但是,如果消息是高优先级消息,则我必须将头部h1指定为“已收到高优先级警报”。

我尝试了一下,但是当我取消注释代码中的h1时,它会返回错误。怎么做 ?。

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>High priority alert has been received !!!</title>
</head>
<body>
    <p>
        <%
           out.println("\n");
           String MESSAGEHighPrio = (String)this.getServletContext().getAttribute("MESSAGEFromHighPrioSIPServlet");
           if (MESSAGEHighPrio == null) {
               out.println("No high priority alerts have been received yet.");
               String MESSAGELowPrio = (String)this.getServletContext().getAttribute("MESSAGEFromLowPrioSIPServlet");
               if(MESSAGELowPrio == null){
                  out.println("No low priority alerts have been received yet");
                  }
               else {
                  // --> <h1>Low priority alert has been received !!!</h1>
                   out.println("Address: " + MESSAGELowPrio + "\n");
               }
           }

           else{
               // --> <h1>High priority alert has been received !!!</h1>
               out.println("Address: " + MESSAGEHighPrio + "\n");
           }
          %>
    </p>

1 个答案:

答案 0 :(得分:1)

您不能将HTML代码放在JSP标记中。

尝试这种方法

<p>
    <%
       out.println("\n");
       [...]
         out.println("<h1>Low priority alert has been received !!!</h1>");
       [...]
      %>
</p>

注意:还要考虑在JSP之外进行计算和条件。不要在演示文稿中混淆逻辑。