1. Built-in Label (Action label)
Built-in tags do not need to import JSP page tags
1), Forward: forwarding of the request, the format is as follows
<%--function with this same <%request.getrequestdispatcher ("/forward2.jsp?name=gqxing"). Forward (request, response);% > --%> <jsp:forward page= "/forward2.jsp" > <jsp:param value= "gqxing" name= "name"/> <jsp:param value= "123456" name= "password"/> </jsp:forward>
2), include Tags: used to include pages,
Contains and contains pages that are translated into Java source files and then merged together before they are run. (Translate and merge first), dynamically include
The format is as follows:
<jsp:include page= "/common/header.jsp" ></jsp:include>
But it has a certain difference from the include directive that was previously learned.
(1), Format difference:
<jsp:include page= "/common/header.jsp" ></jsp:include><% @include file= "/common/header.jsp"%>
(2), Parameter transfer difference:
Dynamic inclusion can pass parameters, static delivery cannot pass resources
<jsp:include page= "/common/head.jsp" > <jsp:param value= "gqxing" name= "name"/> </jsp: Include>
(3), the principle is different:
Static inclusions: Merge First, then translate, dynamic resources: first translation and merging
In the static contains only the home page (the body of the page, the page containing it) is compiled into a Java file, while the included pages are merged directly in the body part of the home page, and in the dynamic inclusion, but does not have this feature, the included page and the homepage are compiled together, and in the home page by means of removing the included page, To achieve the purpose of the merger, the merger method is as follows:
Org.apache.jasper.runtime.JspRuntimeLibrary.include (Request, Response, "/common/header.jsp", out, false);
2, Jstl (Java standard tag libarary) Java Standards Tag Library(1), Core Tag library:
Import of Tags: specific
<% @taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
(1) Set label, save data
<%--set label save data (data saved to domain object, saved in page field by default) --%> <c:set var= "name" value= "gqxing" scope= "Request" >< /c:set> ${requestscope.name}
(2), out tag, get data
<%--out Tags: Get data default : When value is null, use the defaults while the simple El expression does not have this function ' escapexml= ': Whether to transfer value value, the default is true, That is, escape --%> <c:out value= "${name}" default= "
(3), if label: single-condition judgment
<%--if Tags: single condition judgment--%> <c:if test= "${10>5}" >
(4),-choose+when+otherwise label, multi-condition judgment
<%--choose+when+otherwise label, multi-conditional judgment--%> <c:set var= "score" value= "Up" ></c:set> <c: choose> <c:when test= "${score>=90 && score<=100}" > excellent </c:when> <c:when test = "${score>=80 && score<90}" > Good </c:when> <c:when test= "${score>=60 && SCORE<80} "> Pass </c:when> <c:otherwise> less than grid </c:otherwise> </c:choose>
(5), Foreach Loop
Iterate through the list collection first
<%--foreach Cycle begin: Specifies where to start, default is 0 end: Specifies the end position of step: Specifies the step shape as for the for (i=1;i<10;i++) i++ items: The data that needs to be traversed, usually the set var: the name of each element, in order to be able to take varstatus in the loop body : The state object that is currently traversing the element. (Count property: Current position, starting from 1) --%> <% list<student> List =new arraylist<student> (); List.add (New Student ("GQX", +)); List.add (New Student ("gqxing",)); List.add (New Student ("guoqingxing",)); Pagecontext.setattribute ("list", list); %> <c:foreach begin= "0" end= "2" step= "1" items= "${list}" var= "Student" varstatus= "Varsta" > ordinal: ${ varsta.count}--Name: ${student.name}--Age:${student.age}<br> </c:forEach>
Traverse a map key-value pair
<%//map map<string,student> map=new hashmap<string,student> (); Map.put ("001", New Student ("GQX", +)); Map.put ("002", New Student ("gqxing",)); Map.put ("003", New Student ("guoqingxing", 22));//Put into the domain to Pagecontext.setattribute ("map", map); %> <c:foreach begin= "0" end= "2" step= "1" items= "${map}" var= "entry" varstatus= "Varstar" > ordinal: ${ Entry.key}--Name: ${entry.value.name}--Age: ${entry.value.age}<br> </c:forEach>
(6), Fortoken: Looping a special string
<%--fortoken: Loop Special string--%> <% string str= "java-php-net-photoship-c++"; Pagecontext.setattribute ("str", str); %> <c:fortokens items= "${str}" delims= "-" var= "s" varstatus= "Varstar" > ${varstar.count}--${s} <br> </c:forTokens>
(7), redirect: redirect
<%--redirect: redirect--%> <c:redirect url= "http://www.baidu.com" > </c:redirect>
JSP's built-in tags and jstl tags