日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JSTL技术

發布時間:2023/12/1 javascript 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JSTL技术 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.JSTL概述

JSTL(JSP Standard Tag Library),JSP標準標簽庫,可以嵌入在jsp頁面中使用標簽的形式完成業務邏輯等功能。jstl出現的目的同el一樣也是要代替jsp頁面中的腳本代碼。JSTL標準標準標簽庫有5個子庫,但隨著發展,目前常使用的是他的核心庫

標簽庫標簽庫的URI前綴
Corehttp://java.sun.com/jsp/jstl/corec
I18Nhttp://java.sun.com/jsp/jstl/fmtfmt
SQLhttp://java.sun.com/jsp/jstl/sqlsql
XMLhttp://java.sun.com/jsp/jstl/xmlx
Functionshttp://java.sun.com/jsp/jstl/functionsfn

2.JSTL導入

需要導兩個包:

jstl.jar standar.jar

使用jsp的taglib指令導入核心標簽庫

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

3.JSTL核心庫的常用標簽

1)<c:if test=””>標簽
其中test是返回boolean的條件
2)<c:forEach>標簽
使用方式有兩種組合形式:
示例:

1)遍歷List的值

2)遍歷List的值

3)遍歷Map<String,String>的值

4)遍歷Map<String,User>的值

5)遍歷Map<User,Map<String,User>>的值
entry.key-----User
entry.value------List<String,User>

//forEach.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page import="beyond.domain.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body><%//模擬List<String> strListList<String> strList = new ArrayList<String>();strList.add("beyond0");strList.add("beyond1");strList.add("beyond2");strList.add("beyond3");request.setAttribute("wsq", strList);//遍歷List<User>的值List<User> userList = new ArrayList<User>();User user1 = new User();//list集合中的第一個元素user1.setId(2);user1.setName("qibao");user1.setPassword("wsq");userList.add(user1);//list集合中的第二個元素User user2 = new User();user2.setId(3);user2.setName("yanyu");user2.setPassword("wsq");userList.add(user2);application.setAttribute("qb", userList);//遍歷Map<String,String>的值Map<String,String> strMap = new HashMap<String,String>();strMap.put("name", "hjj");strMap.put("age", "32");strMap.put("addr", "香港");strMap.put("email", "hjj@qq.com");session.setAttribute("strMap", strMap);//遍歷Map<String,User>的值Map<String,User> userMap = new HashMap<String,User>();userMap.put("user1", user1);userMap.put("user2", user2);session.setAttribute("userMap", userMap); /* //遍歷Map<User,Map<String,User>>的值Map<User,Map<String,User>> mapMap = new HashMap<User,Map<String,User>>();mapMap.put(user1,userMap);mapMap.put(user2,userMap);session.setAttribute("mapMap", mapMap); */%><h1>取出strList的數據</h1><c:forEach items="${wsq}" var="str">${str}<br/></c:forEach><h1>取出userList的數據</h1><c:forEach items="${qb}" var="user" >user的name:${user.name}------------user的password:${user.password} <br/></c:forEach><h1>取出strMap的數據</h1><c:forEach items="${strMap}" var="entry">${entry.key}---------------${entry.value}<br/></c:forEach><h1>取出userMap的數據</h1><c:forEach items="${userMap}" var="entry" >${entry.key}--------------${entry.value.id}--------------${entry.value.name}--------------${entry.value.password}<br/></c:forEach><%-- <h1>取出mapMap的數據</h1><c:forEach items="${mapMap}" var="enter">${entry.key.key}--------------${entry.value.value.id}--------------${entry.value.name}--------------${entry.value.password}<br/></c:forEach> --%></body> </html> //userLogin.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%@ page import= "beyond.domain.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body><!-- 模擬用戶已經登陸成功 --><% User user = new User();user.setId(1014);user.setName("wsq");user.setPassword("wsq");session.setAttribute("user", user);/* 把user放到session域當中 */%> </body> </html> //jstl.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!-- 通過taglib導入jstl的core庫 --> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body><!-- jstl標簽經常會和el表達式(從域中取東西)配合使用 --><%request.setAttribute("count", 1014);%><c:if test="${count==1014}">nice you are right!!</c:if><!-- test代表的是一個返回boolean的表達式條件,要么是true要么是false,如果是true進入if標簽內部,但是,注意這里沒有else標簽!!! --><c:if test="1==1">beyond</c:if><c:if test="1!=1">sq</c:if><!-- 第一種組合方式 --><!-- forEach模擬for(int i=0;i<=5;i++){System.out.println(i);} --><c:forEach begin="0" end="5" var="i">${i}<br/></c:forEach><!-- 也就是從0開始到5結束每次將值賦值給i然后通過el表達式輸出i的值,每輸出一個就換行 --><!-- 第二種組合方式 --><!-- forEach模擬增強for循環 productList----List<Product>for(Product product : productList){}System.out.println(product.getPname());--><!-- items:是一個集合或者數組 var:代表集合中的某一個元素 --><c:forEach items="${productList}" var="pro">${pro.pname}</c:forEach></body> </html>

總結

以上是生活随笔為你收集整理的JSTL技术的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。