Directive:编译指令;编译期间的指令
格式:<%@ 属性="属性值" %>
常见的Directive:
page
include[以后常用,必须掌握]
taglib
1.page的下面四个属性最常用:
<%@ page import="java.util.*,com.servlet.*"
errorPage="……"
isErrorPage="……"
contentType="test/html;charset=UTF-8" %>
2.include属性:
<%@ include file="pageUrl"%>
例如:
<%@ include file="test.jsp" %>
先把test.jsp文件中的内容原封不动的放入到这个地方,然后编译,即在还没开始编译之前就已经组成一个文件了
限制:由于是编译型的指令,这种指令是不能往里面传参数,因为现在还没开始执行的,只是编译,是不可能能够传参数的
演示一个实验:
//TestError.jsp,假如这个页面
<%@ page language="java"%> <%@ page import="java.util.*" %> <%@ page pageEncoding="UTF-8" %> <%@ page contentType="text/html;charset=UTF-8" %> <%--出错后输出ErrorPage.jsp的内容 --%> <%@ page errorPage="ErrorPage.jsp" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'ErrorPage.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% String s = "123str"; int value = Integer.parseInt(s); out.println("s="+s+" value="+value); %> </body> </html>