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

JSP概念以及JSP的指令

时间:2022-12-21 13:33:29浏览次数:30  
标签:概念 导入 JSP 指令 jsp include Hello 页面

JSP概念

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

  格式:

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

  分类:

    1.page:配置JSP页面的

    2.include:页面包含的,导入页面的资源文件

    3.taglib:导入资源

 

Page指令

page:配置JSP页面

  contentType:等同于response.setContentType(),响应消息体以及字符集

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

    2.设置当前jsp页面的编码(只能是高级的IDE才能生效,如果使用低级工具。则需要设置pageEncoding属性设置当前页面的字符集)

  language:编程语言

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" language="java" %>

  import:导包

 

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

<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" errorPage="500.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>
<br/>
<a href="hello-servlet">Hello Servlet</a>

    <%
        List list = new ArrayList();
        int o = 3/0;
    %>
</body>
</html>

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

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

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

<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %>
<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>

home.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="top.jsp" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h3>主体信息</h3>
</body>
</html>

 

taglib:导入资源

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

prefix:是前缀,自定义

<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" errorPage="500.jsp" %>

<%@ taglib prefix="hello" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>
<br/>
<a href="hello-servlet">Hello Servlet</a>

    <%
        List list = new ArrayList();
        int o = 3/0;
    %>

    <hello:if test=""></hello:if>

</body>
</html>

 

标签:概念,导入,JSP,指令,jsp,include,Hello,页面
From: https://www.cnblogs.com/qihaokuan/p/16996034.html

相关文章