(一)jsp指令
jsp指令包括:page指令、include指令、taglib指令
(二)page指令的作用
语法:
<%@ page 属性名1=“属性值1”..... 属性名n=“属性值n”%>
1、import:在指定jsp页面导入java类或包。
2、session:限制session是否可用,默认为true表示可用,fasle不可用。
3、iserrorpage:指定jsp页面是否为处理异常错误页面,当设置为true时,exception才可用,默认为false.
4、errorpage=”url”:当页面产生异常是跳转的路径。
5、contenttype=”text/html;charset=utf-8”:根据出现判断文档类型。
6、pageencoding:指定页面编码格式。
7、autoflush=”true|false”:指明缓冲区的否自动清除,默认为true
8、info=”text”:描述此jsp页面的相关信息
9、isthreadsafe=”false|true”:是否允许多线程使用该页面,默认为true
10、buffer=”8kb”:输出流是否有缓存区,默认为8kb
11、extends=”class”:指明该jsp页面产生的servlet所继承的父类
(三)include指令引入文件
<%@ include file="文件路径(绝对、相对都可以)"%>
实例演示
<%@page import="java.util.date"%>
<%@ page language="java" contenttype="text/html; charset=utf-8"
pageencoding="utf-8"%>
<!--jsp中嵌入html -->
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "https://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>jsp表达式</title>
</head>
<body>
<center>
<%="当前时间为:"+new date().tolocalestring() %>
</center>
</body>
</html>
----------
<%@ page language="java" contenttype="text/html; charset=utf-8"
pageencoding="utf-8"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "https://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>
<%@ include file="date.jsp" %>
</body>
</html>
输出:

(三)与标签相关的taglib指令
导入包:jstl-1.2.jar、jstl-standard.jar
<%taglib uri="tagliburi" prefix="tagpre"%> uri:表示自定义标签库的存放位置 prefix:区分不同标签库的标签名
实例演示:
<%@ page language="java" contenttype="text/html; charset=utf-8"
pageencoding="utf-8"%>
<%@ taglib uri="http://www.51sjk.com/Upload/Articles/1/0/248/248602_20210624000550167.jpg prefix="c"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "https://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>jsp taglib指令演示</title>
</head>
<body>
<center>
<%--param读取地址栏数据 --%>
<c:out value="${param.username} "><br/> </c:out>
年龄=18
</center>
</body>
</html>
在浏览器地址栏输出:https://localhost/project/index.jsp?username=“kaina”:
输出:

Ching商业地产