JSP tag technology

  1. Write a lot of java code in JSP pages can lead to a JSP page html code and java code mixed together, will result page is very confusing, difficult to maintain

    First introduced JSTL jar package, introduced through the tag library JSTL taglib

  

  2. So in the version of JSP 2.0, sun proposed JSP tag technology is recommended to use tags to track problem java code JSP pages, and recommend, a line of java code JSP pages not to appear later JSP2.0.

  

  3.EL expression

    EL expression can be very easily access data in JSP may be replaced JSP expressions (<% =%>) JSP page

    The basic structure: Expression $ {}

    EL only get can not be set! ! !

    EL can not only get to traverse! ! !

    EL expression provides the following functions:

      (1) EL can get constant, variable (must be deposited in the domain), the value of the expression

<%
    String name="aaa";
    pageContext.setAttribute("name",name);
%>

${ name }

 

      (2) EL array or collection of data may be acquired in the domain

      <c:forEach items="${list}" var="prod">
            <tr>
                <td><%
                List<Porduct> list = (List<Porduct>)request.getAttribute("list"); 
                Porduct po = list.get(0);
                out.write(String.valueOf(po.getId()));
                
                %>
                <%=po.getId()%>
                <% out.write("hello"); %>
                </td>
                <td>${prod.name }</td>
                <td>${prod.name }</td>
                <td>${prod.des }</td>
                <th>
                    <!-- <span onclick="del()">删除</span>
                    <div id="firstdiv"></div>
                    <span onclick="upd()">修改</span> -->
                    <a id="delProd" href="#">删除</a>|
                    <a id="updProd"> Edit </a>"#"= href
                </th>
            </tr>
            </c:forEach>

 

EL fetch data from the domain, the domain of the lookup order:

Page > Request > Session > Application

 

Guess you like

Origin www.cnblogs.com/gxlaqj/p/11409441.html