其他分享
首页 > 其他分享> > JSP的概述以及JSP的指令

JSP的概述以及JSP的指令

作者:互联网

JSP的概述

  1、作用:用于配置JSP页面,导入资源文件

  2、格式:

      <%@ 指令名称 属性名1=属性值1 属性名2=属性值2......%>

  3、分类

    1、page:配置JSP页面

    2、include:页面包含的。导入页面的资源文件

    3、taglib:导入资源

 

 

Page指令

page:配置JSP页面

  contentType:等同于response.setContentType()

    1、设置响应体的mime类型以及字符集

    2、设置当前jsp页面的编码(设置pageEncoding属性设置当前页面的字符集)

  

  import:导包

  

  errorPage:当前页面发生异常后,会自动跳转到指定的错误页面

<%@ page contentType="text/html;charset=UTF-8" errorPage="500.jsp" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <%
    int i = 3/0;
  %>
  </body>
</html>

  isErrorPage:标识当前页面是否是错误页面

    true:是,可以使用内置对象exception

    false:否,默认值,不可以使用内置对象exception

<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h1>正忙...</h1>

    <%
        String message = exception.getMessage();
        out.print(message);
    %>
</body>
</html>

 

 

 

include指令

include:页面包含的。导入页面的资源文件

top.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<h1>页面logo页面标题</h1>
<%@ page contentType="text/html;charset=UTF-8"  language="java" %>
<%@include file="top.jsp"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h1>正忙...</h1>
</body>
</html>

 

 

 

 

taglib指令

taglib:导入资源

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
prefix:前缀,自定义
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <c:if test=""></c:if>
</body>
</html>

 

标签:Title,导入,概述,指令,JSP,taglib,include,页面
来源: https://www.cnblogs.com/xjw12345/p/16587637.html