-1

什么时候应该使用 <%- 标签?由于 <%- 未转义,它不会让应用程序容易受到攻击吗?

4

2 回答 2

1

当您在变量中信任HTML时,您会使用它。

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

于 2017-07-25T18:55:51.897 回答
0

我告诉你什么时候你需要使用每个

案例 1 <% ** 声明 JAVA 类和对象** %>

我使用这种形式,当我需要声明 ArrayList 时,例如 Notice & Events,之后我可以使用 Form 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>

我希望我有帮助,问候

于 2017-07-25T20:22:25.153 回答