Jsp腳本元素的三種格式:
表達式:
<%=exprssion%> 將表達式的值輸出到前臺。
<jsp:expression>Java Expression</jsp:expresion>
Scriptlet:
<%Java code%>將Java代碼塊插入到Servlet的service方法
<jsp:scritplet>code</jsp:scritptlet>
Declaration:<%!code%>聲明,在任何方法之外,如果聲明一個變量那麼這個變量就是類的屬性。
Jsp中的隱含對象:request,response,out,session,application,config,pageContext,page
跳轉:
request.sendRedirect("URL");
request.getRequestDispacher("URL").forward(request,reponse);
Jsp指令標籤:
<%@directive attribute="value" aattribute2="value2"..%>
<%@page %>
<%@include file=""%>
<%@taglib uri="" prefix=""%>
Jsp動作指令標籤:
<jsp:include file="url"></jsp:include>
<jsp:forward page="url"/>
<jsp:useBean id="" class="" scope="">
<jsp:setProperty name="" property="" value=""/>
<jsp:setProperty name="" property="" value=""/>
</jsp:userBean>
EL 語法結構:
1、${expression}
2、[] . 來去對象的屬性([]可以動態的取值)
3、${varName}聲明變量
4、可訪問的元素類型:MAP、LIST、Arrary、JavaBean
5、EL常用隱含屬性:
${param.inputName}相當於 request.getParameter ("inputName");
? ${paramValues.inputName[i]}相當於request.getParamterValues("inputName")[i]
? ${pageScope.userBeanId.propertyName}獲得scope=“page” id=“userBeanId”的javaBean對象的屬 性值.
${requestScope.attrName}相當於 request.getAttribute(“attrName”)
${sessionScope.attrName}相當於 session.getAttribute(“attrName”)
${applicationScope.attrName}相當於? application.getAttribute(“attrName”)
訪問JavaBean:${beanId.fildName} 相當於 <%=beanId.getFiledName()>
訪問Map類型:${mapName.kayName}相當於 mapName. get(“kayName”)
訪問List類型:${listName[i]}相當於 listName.get(i)
?
? <%@ page isELIgnored="false" %>可以使用EL
JSTL 語法結構:
核心標籤庫:
1、<c:out value="" default="" escapeXml=""></c:out>用於計算一個表達式並將結果輸出
2、<c:set var="" value="" scope="" target="" property=""></c:set>用於設置範圍變量的值或者 javabean 對象的屬性
3、<c:remove var="" scope=""/> 相對 <c:set> 其作用是移除範圍變量.
4、<c:catch var=”exception”>
<%
可能產生異常
%>
</c:catch>
${exception}<br>
5、<c:if test="" var="" scope="" >
This is your first visit .
</c:if>
6、<c:choose> 實現互斥條件執行,類似於 java 中的 if else.
<c:when test="">
out1
</c:when>
<c:when test="">
out2
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
7、<c:forEach items="${arry}" var="item">
${item.fileName}
</c:forEach>
8、<c:forEach begin="0" end="2" var="i" step="1">
${array[i]}<br>
</c:forEach>
?
09 12 11 Java Web學習筆記-Jsp簡單總結
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.