當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Java web后端7JSTL
生活随笔
收集整理的這篇文章主要介紹了
Java web后端7JSTL
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
概括
下載jstl的jar包
官網:https://mvnrepository.com/
網址1:https://search.maven.org/
在pomxml中插入依賴:
再刷新Maven即可
使用jstl
在jsp頁面中填寫
使用jsp指令引入jstl標簽庫
<c:out>標簽
HTML編碼:空格: 小于:<大于:>
常與el表達式配合使用:
獲取http請求消息體中username參數的值(用戶輸入的值):${param.username}
如:
案例:
代碼:
<c:if>標簽
相當于java中的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>標簽
案例:
代碼:
案例2:九九乘法表
代碼:
總結
以上是生活随笔為你收集整理的Java web后端7JSTL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新手该怎么投资理财 新手要如何进行投资理
- 下一篇: gradle idea java ssm