指令
jsp页面顶部的 <%@ %>
标签就是jsp指令
参数有三种
<%@ page args...%>
<%@ include file="" %>
<%@ taglibs args...%>
page指令
page参数的jsp指令建议写在页面上面
以下两种代码示例,选择一种即可
代码示例1
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%--如果页面出错,则定位到自定义的错误页面--%>
<%@ page errorPage="error/500.jsp" %>
<html>
<body>
<h1>HelloWorld</h1>
<%
int i = 1/0;
%>
</body>
</html>
代码示例2
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
<error-page>
<error-code>500</error-code>
<!--/代表当前项目,必须加上-->
<location>/error/500.jsp</location>
</error-page>
</web-app>
显式声明错误页面
<%@ page isErrorPage="true" %>
不要用于正常代码,要用在404或500这种错误页面
防止中文乱码
如果 charset=UTF-8
不能解决中文乱码问题
就加上如下代码
<%@ page pageEncoding="UTF-8" %>
include指令
footer.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>这是footer</h1>
</body>
</html>
header.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>这是header</h1>
</body>
</html>
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%@ include file="header.jsp"%>
<h1>这是主页</h1>
<%@ include file="footer.jsp"%>
</body>
</html>
taglib指令
这里还没写...