【问题标题】:What are the benefits of using <%- tag v/s <%= tag in ejs?在 ejs 中使用 <%- tag v/s <%= tag 有什么好处?
【发布时间】:2017-07-26 04:22:25
【问题描述】:

什么时候应该使用

【问题讨论】:

  • 这取决于输出的来源。如果因为不受信任而需要对其进行转义,则应明确将其转义。其他时候你真的不想逃避输出。这一切都取决于你。

标签: javascript html tags ejs html-escape


【解决方案1】:

当你在一个变量中有 trusted HTML 时,你会使用它。

例如,如果您要通过 Markdown 解析器运行一大块数据以生成 HTML。

【讨论】:

    【解决方案2】:

    当你需要使用每个时,我会告诉你

    案例 1

    我使用这个表格,当我需要声明ArrayList时,例如Notice & Events,之后我可以使用表格1在一些表格中显示数据

    <%
        boolean flag = false;
        ArrayList<NoticiasyEventos> arrayNoticiasyEventos = (ArrayList<NoticiasyEventos>) request.getAttribute("arrayNoticiasyEventos");
    
        if(arrayNoticiasyEventos != null){
            flag = true;
        }
    %>
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    
    </body>
    </html>
    

    案例 2 值 =>

    在这种情况下,我需要从 Servlet 中获取特定的值,记住我声明了 ArrayList 然后我可以使用这个数组来获取我需要的值

                                                <table>
                                                    <thead>
                                                        <tr>
                                                            <th>MÓDULO</th>
                                                            <th>CATEGORÍA</th>
                                                            <th>TÍTULO</th>
                                                            <th>RESUMEN</th>
                                                            <th>DETALLE</th>
                                                            <th>FECHA NOTICIA</th>
                                                            <th>IMAGEN</th>
                                                            <th>MODIFICAR</th>
                                                            <th>ESTADO</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <%
                                                        if(flag){
    
                                                            for (int i = 0; i < arrayNoticiasyEventos.size(); i++) {
                                                        %>
                                                        <tr>
                                                            <td ><%=arrayNoticiasyEventos.get(i).getDes_mod()%></td>
                                                            <td ><%=arrayNoticiasyEventos.get(i).getDes_cat()%></td>
                                                            <td ><%=arrayNoticiasyEventos.get(i).getDes_tit()%></td>
                                                            <td ><%=arrayNoticiasyEventos.get(i).getDet_res()%></td>
                                                            <td ><%=arrayNoticiasyEventos.get(i).getDes_det()%></td>
                                                            <td ><%=arrayNoticiasyEventos.get(i).getFec_not()%></td>
                                                            <td align='center'><img id='myImg' src='<%=arrayNoticiasyEventos.get(i).getUrl_img()%>' alt='<%=arrayNoticiasyEventos.get(i).getDes_tit()%>' width='80' height='65' onclick='modalI(this);' /></td>
                                                            <td align="center"><button class='btn green-meadow' style='width: 107px;' data-target='#modal_modificar_noticias_eventos' data-toggle='modal' onclick='buscarNoticiaXId(<%=arrayNoticiasyEventos.get(i).getCod_not_eve()%>);'>EDITAR</button></td>
                                                            <td align="center"><button class='btn blue' style='width: 107px;' data-target='#modal_desabilitar_noticia' data-toggle='modal' onclick='deshabilitarNoticiaXId(<%=arrayNoticiasyEventos.get(i).getCod_not_eve()%>);'>ACTIVO</button></td>
                                                            %>
                                                        </tr>
                                                        <%
                                                            }
                                                        }
                                                        %>
                                                    </tbody>
                                                </table>
    

    希望对您有所帮助,问候

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 1970-01-01
      • 2012-05-30
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多