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

歡迎訪問 生活随笔!

生活随笔

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

javascript

Java web后端7JSTL

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

概括




下載jstl的jar包

官網:https://mvnrepository.com/
網址1:https://search.maven.org/
在pomxml中插入依賴:

<dependency><groupId>taglibs</groupId><artifactId>standard</artifactId><version>1.1.2</version></dependency><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency>

再刷新Maven即可

使用jstl

在jsp頁面中填寫
使用jsp指令引入jstl標簽庫

<c:out>標簽

HTML編碼:空格:&nbsp;小于:&lt;大于:&gt;
常與el表達式配合使用:
獲取http請求消息體中username參數的值(用戶輸入的值):${param.username}
如:

<%--使用c標簽--%> <c:out value="${param.username}" default="unknown"/>





案例:

代碼:

<%--使用c標簽1--%> <c:out value="${param.username}" default="unknown"/><%--使用c標簽2--%> <c:out value="${param.username}" escapeXml="true"> <%-- 輸出:<a href="https://editor.csdn.net/md?not_checkout=1&articleId=121206585">CSDN</a>--%><a href="https://editor.csdn.net/md?not_checkout=1&articleId=121206585">CSDN</a> </c:out>

<c:if>標簽

相當于java中的if


案例:

<c:set value="1" var="test" property="test"/> <%--c:if語句--%> <c:if test="${test eq 1}">this is your first time! </c:if>

<c:choose>標簽


案例:成績判斷

html代碼:

<form action="score.jsp"><label>請輸入你的成績:</label><br/><input type="text" name="score"><br/><input type="submit" value="提交"><input type="reset" value="重置"><br/> </form>

c:choose代碼:

<c:choose><c:when test="${empty param.score}">你還沒有輸入,請先輸入!</c:when><c:when test="${!param.score.matches('-*[0-9]+')}">你輸入的成績不為數字,請重新輸入!</c:when><c:otherwise><c:choose><%--成績越界!--%><c:when test="${(param.score lt 0) or (param.score gt 100)}">你輸入的成績超出范圍!</c:when><%--0<=score<=100100 滿分90-99 優秀80-89 優良70-79 良好60-69 及格0-59不及格--%><c:when test="${param.score eq 100}">滿分!</c:when><c:when test="${(param.score ge 99) and (param.score le 90) }">優秀!</c:when><c:when test="${(param.score ge 80) and (param.score le 89) }">優良!</c:when><c:when test="${(param.score ge 70) and (param.score le 79) }">良好!</c:when><c:when test="${(param.score ge 60) and (param.score le 69) }">及格!</c:when><c:when test="${(param.score ge 0) and (param.score le 59) }">不及格!</c:when><c:otherwise>你輸入的不是數字!</c:otherwise></c:choose></c:otherwise> </c:choose>

總代碼:

<%@ page import="java.util.regex.Pattern" %> <%@ page import="java.util.regex.Matcher" %><%--Created by IntelliJ IDEA.User: DQDate: 2021/11/8Time: 15:08To change this template use File | Settings | File Templates. --%><%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head><title>成績</title> </head> <body><form action="score.jsp"><label>請輸入你的成績:</label><br/><input type="text" name="score"><br/><input type="submit" value="提交"><input type="reset" value="重置"><br/> </form><hr/> 你成績的等級是:<br/><c:choose><c:when test="${empty param.score}">你還沒有輸入,請先輸入!</c:when><c:when test="${!param.score.matches('-*[0-9]+')}">你輸入的成績不為數字,請重新輸入!</c:when><c:otherwise><c:choose><%--成績越界!--%><c:when test="${(param.score lt 0) or (param.score gt 100)}">你輸入的成績超出范圍!</c:when><%--0<=score<=100100 滿分90-99 優秀80-89 優良70-79 良好60-69 及格0-59不及格--%><c:when test="${param.score eq 100}">滿分!</c:when><c:when test="${(param.score ge 99) and (param.score le 90) }">優秀!</c:when><c:when test="${(param.score ge 80) and (param.score le 89) }">優良!</c:when><c:when test="${(param.score ge 70) and (param.score le 79) }">良好!</c:when><c:when test="${(param.score ge 60) and (param.score le 69) }">及格!</c:when><c:when test="${(param.score ge 0) and (param.score le 59) }">不及格!</c:when><c:otherwise>你輸入的不是數字!</c:otherwise></c:choose></c:otherwise> </c:choose></body> </html>

<c:forEach>標簽



案例:

代碼:

<%@ page import="java.util.Map" %> <%@ page import="java.util.HashMap" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%--Created by IntelliJ IDEA.User: DQDate: 2021/11/8Time: 15:24To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> <%--c:forEach1--%> <%String[] fruits = {"apple", "orange"}; %> <c:forEach var="name" items="<%=fruits%>">${name}<br/> </c:forEach><%--c:forEach2--%> <%Map map=new HashMap();map.put("name1","dq1");map.put("name2","dq2"); %><c:forEach var="m" items="<%=map%>">${m.key}==${m.value}<br/> </c:forEach><%--forEach3:普通for方式--%> <c:forEach var="i" begin="1" end="10">${i}<br/> </c:forEach> </body> </html>

案例2:九九乘法表

代碼:

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head><title>九九乘法表改寫</title> </head> <body> <table><tr><c:forEach var="i" begin="1" end="9"><c:forEach var="j" begin="1" end="${i}"><td style="border: green solid 2px;padding: 1px">${i}*${j}=${i*j}</td></c:forEach></tr></c:forEach> </table> </body> </html>

總結

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

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