문제

I want to assign the header h1 as "Low priority alert has been received"if the received message in the SIP Servlet is a Low priority message. But if the message is a high priority message instead, I have to assign the header h1 as "High priority alert has been received" instead.

I gave it a try, but it returns errors, when I uncomment the h1s in the code. How to do it ?.

<%@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>
도움이 되었습니까?

해결책

You can not put HTML code inside the JSP tags like that.

Try with this approach

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

Note: Also consider to make the calculations and conditions outside the JSP. Do not mess logic with the presentation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top