jsp taglib指令

JSP Directives are used to give special instruction to container for translation of JSP to Servlet code. JSP Directives are placed between <%@ %>.

JSP指令用于为容器提供特殊指令,以将JSP转换为Servlet代码。 JSP指令位于<%@ %>

JSP指令 (JSP Directives)

JSP provides three directives for us to use;

JSP提供了三个指令供我们使用。

  1. JSP page directiveJSP页面指令
  2. JSP include directiveJSP包含指令
  3. JSP taglib directiveJSP taglib指令

Every jsp directive has a set of attributes to provide specific type of instructions. So usually a JSP directive will look like

每个jsp指令都有一组属性来提供特定类型的指令。 因此,通常JSP指令看起来像

<%@ directive attribute="value" %>

.

If you have directly landed here, you might want to check out JSP Tutorial for Beginners and JSP Implicit Objects.

如果您直接登陆这里,则可能要查看《初学者的JSP教程》和《 JSP隐式对象》 。

JSP页面指令 (JSP page directive)

page directive provides attributes that get applied to the entire JSP page. page directive has a lot of attributes that we will look at now. We can define multiple attributes in a single page directive or we can have multiple page directives in a single JSP page.

page指令提供了应用于整个JSP页面的属性。 page指令具有许多我们现在要看的属性。 我们可以在单个页面指令中定义多个属性,也可以在单个JSP页面中具有多个页面指令。

  1. import attribute: This is one of the most used page directive attribute. It’s used to instruct container to import other java classes, interfaces, enums etc. while generating servlet code. This is similar to import statements in java classes, interfaces. An example of import page directive usage is:

    <%@ page import="java.util.Date,java.util.List,java.io.*" %>

    import属性 :这是最常用的页面指令属性之一。 它用于指示容器在生成Servlet代码时导入其他Java类,接口,枚举等。 这类似于java类,接口中的import语句。 导入页面指令用法的一个示例是:

  2. contentType attribute: This attribute is used to set the content type and character set of the response. The default value of contentType attribute is”text/html; charset=ISO-8859-1″. We can use it like below.
    <%@ page contentType="text/html; charset=US-ASCII" %>

    contentType属性 :此属性用于设置响应的内容类型和字符集。 contentType属性的默认值为“ text / html; charset = ISO-8859-1“。 我们可以像下面这样使用它。

  3. pageEncoding attribute: We can set response encoding type with this page directive attribute, its default value is “ISO-8859-1”.
    <%@ page pageEncoding="US-ASCII" %>

    pageEncoding属性 :我们可以使用此page指令属性设置响应编码类型,其默认值为“ ISO-8859-1”。

  4. extends attribute: This attribute is used to define the super class of the generated servlet code. This is very rarely used and we can use it if we have extended HttpServlet and overridden some of it’s implementations. For example;
    <%@ page extends="org.apache.jasper.runtime.HttpJspBase" %>

    extend属性 :此属性用于定义生成的servlet代码的超类。 这很少使用,如果扩展了HttpServlet并覆盖了其中的某些实现,则可以使用它。 例如;

  5. info attribute: We can use this attribute to set the servlet description and we can retrieve it using Servlet interface getServletInfo() method. For example;
    <%@ page info="Home Page JSP" %>

    info属性 :我们可以使用此属性来设置servlet描述,并可以使用Servlet接口getServletInfo()方法检索它。 例如;

  6. buffer attribute: We know that JspWriter has buffering capabilities, we can use this attribute to set the buffer size in KB to handle output generated by JSP page. Default value of buffer attribute is 8kb. We can define 16 KB buffer size as;
    <%@ page buffer="16kb" %>

    buffer属性 :我们知道JspWriter具有缓冲功能,我们可以使用此属性设置缓冲区大小(以KB为单位),以处理JSP页面生成的输出。 缓冲区属性的默认值为8kb。 我们可以将16 KB的缓冲区大小定义为:

  7. language attribute: language attribute is added to specify the scripting language used in JSP page. It’s default value is “java” and this is the only value it can have. May be in future, JSPs provide support to include other scripting languages like C++ or PHP too.
    <%@ page language="java" %>

    language属性 :语言属性已添加,以指定JSP页面中使用的脚本语言。 它的默认值是“ java”,这是它唯一的值。 可能在将来,JSP也提供支持以包括其他脚本语言,例如C ++或PHP。

  8. isELIgnored attribute: We can ignore the Expression Language (EL) in JSP using this page directive attribute. Its datatype is Java Enum and default value is false, so EL is enabled by default. We can instruct container to ignore EL using below directive;
    <%@ page isELIgnored="true" %>

    isELIgnored属性 :使用此页面指令属性,我们可以忽略JSP中的表达式语言(EL)。 其数据类型为Java Enum ,默认值为false ,因此默认情况下启用EL。 我们可以使用以下指令指示容器忽略EL;

  9. isThreadSafe attribute: We can use this attribute to implement SingleThreadModel interface in generated servlet. Its an Enum with default value as true. If we set it’s value to false, the generated servlet will implement SingleThreadModel and eventually we will loose all the benefits of servlet multi-threading features. You should never set it’s value to false.
    <%@ page isThreadSafe="false" %>

    isThreadSafe属性 :我们可以使用此属性在生成的servlet中实现SingleThreadModel接口。 一个枚举,默认值为true。 如果将其值设置为false,则生成的servlet将实现SingleThreadModel,最终我们将失去servlet 多线程功能的所有优势。 您永远不要将其值设置为false。

  10. errorPage attribute: This attribute is used to set the error page for the JSP, if the JSP throws exception, the request is redirected to the error handler defined in this attribute. It’s datatype is URI. For example;
    <%@ page errorPage="errorHandler.jsp" %>

    errorPage属性 :此属性用于设置JSP的错误页面,如果JSP引发异常,则请求将重定向到此属性中定义的错误处理程序。 它的数据类型是URI。 例如;

  11. isErrorPage attribute: This attribute is used to declare that current JSP page is an error page. It’s of type Enum and default value is false. If we are creating an error handler JSP page for our application, we have to use this attribute to let container know that it’s an error page. JSP implicit attribute exception is available only to the error page JSPs. For example;
    <%@ page isErrorPage="true" %>

    isErrorPage属性 :此属性用于声明当前JSP页面是错误页面。 它是Enum类型,默认值为false。 如果要为我们的应用程序创建错误处理程序JSP页面,则必须使用此属性使容器知道它是错误页面。 JSP隐式属性异常仅适用于错误页面JSP。 例如;

  12. autoFlush attribute: autoFlush attribute is to control the buffer output. Its default value is true and output is flushed automatically when the buffer is full. If we set it to false, the buffer will not be flushed automatically and if it’s full, we will get an exception for buffer overflow. We can use this attribute when we want to make sure that the JSP response is sent in full or none. For example;
    <%@ page autoFlush="false" %>

    autoFlush属性 :autoFlush属性用于控制缓冲区的输出。 其默认值为true,并且在缓冲区已满时自动刷新输出。 如果将其设置为false,则不会自动刷新缓冲区,如果缓冲区已满,则会获得缓冲区溢出的异常。 当我们要确保完全或完全不发送JSP响应时,可以使用此属性。 例如;

  13. session attribute: By default JSP page creates a session but sometimes we don’t need session in JSP page. We can use this attribute to indicate compiler to not create session by default. It’s default value is true and session is created. To disable the session creation, we can use it like below.
    <%@ page session ="false" %>

    session属性 :默认情况下,JSP页面创建一个会话,但是有时我们不需要JSP页面中的会话。 我们可以使用此属性来指示编译器默认情况下不创建会话。 默认值为true,并创建会话。 要禁用会话创建,我们可以像下面这样使用它。

  14. trimDirectiveWhitespaces attribute: This attribute was added in JSP 2.1 and used to strip out extra white spaces from JSP page output. Its default value is false. It helps in reducing the generated code size, notice the generate servlet code keeping this attribute value as true and false. You will notice no out.write("\n") when it’s true.
    <%@ page trimDirectiveWhitespaces ="true" %>

    trimDirectiveWhitespaces属性 :此属性在JSP 2.1中添加,用于从JSP页面输出中去除多余的空格。 其默认值为false。 它有助于减少生成的代码大小,注意生成的servlet代码将此属性值保持为true和false。 您会发现没有true的out.write("\n")

JSP包含指令 (JSP include directive)

JSP include directive is used to include the contents of another file to the current JSP page. The included file can be HTML, JSP, text files etc. Include directive is very helpful in creating templates for user views and break the pages into header, footer, sidebar sections.

JSP include指令用于将另一个文件的内容包含到当前JSP页面中。 包含的文件可以是HTML,JSP,文本文件等。include指令在为用户视图创建模板并将页面分为页眉,页脚,侧边栏部分时非常有用。

We can include any resources in the JSP page like below.

我们可以在JSP页面中包括任何资源,如下所示。

<%@ include file="test.html" %>

The file attribute value should be the relative URI of the resource from the current JSP page.

文件属性值应该是当前JSP页面中资源的相对URI。

JSP taglib指令 (JSP taglib directive)

JSP taglib directive is used to define a tag library with the prefix that we can use in JSP, we will look into more details in the JSP Custom Tags tutorial.

JSP taglib指令用于定义一个带有我们可以在JSP中使用的前缀的标签库,我们将在JSP Custom Tags教程中研究更多细节。

We can define JSP tag libraries is like below;

我们可以定义JSP标签库,如下所示;

<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>

JSP taglib directive is used in JSP standard tag libraries, please read JSTL Tutorial.

JSP标准标签库中使用了JSP taglib指令,请阅读JSTL教程

That’s all for JSP directives, we will look into Expression Language (EL) and JSP Actions next.

这就是JSP指令的全部内容,接下来我们将研究表达式语言(EL)和JSP动作。

Update: JSP EL and JSP Action Tags articles are live now.

更新JSP ELJSP动作标签文章现已上线。

翻译自: https://www.journaldev.com/2044/jsp-directives-page-include-taglib-example

jsp taglib指令

jsp taglib指令_JSP指令–页面,包含和taglib示例相关推荐

  1. JSP:1. 指令(page  ;include ;taglib)2. 内置对象

    1. 指令 * 作用:用于配置JSP页面,导入资源文件     * 格式:         <%@  指令名称 属性名1=属性值1 属性名2=属性值2 ... %>     * 分类:   ...

  2. JSP的3大指令Page,include,taglib

    一般格式是<%@ 指令名称 属性1="属性值" 属性2="属性值" -%> 指令名称有三种:page,include,taglib <%@ p ...

  3. JAVAWEB开发之Session的追踪创建和销毁、JSP详解(指令,标签,内置对象,动作即转发和包含)、JavaBean及内省技术以及EL表达式获取内容的使用

    Session的追踪技术 已知Session是利用cookie机制的服务器端技术,当客户端第一次访问资源时 如果调用request.getSession() 就会在服务器端创建一个由浏览器独享的ses ...

  4. JAVAWEB开发之Session的追踪创建和销毁、JSP具体解释(指令,标签,内置对象,动作即转发和包括)、JavaBean及内省技术以及EL表达式获取内容的使用...

    Session的追踪技术 已知Session是利用cookie机制的server端技术.当client第一次訪问资源时 假设调用request.getSession() 就会在server端创建一个由 ...

  5. JSP的7个动作指令-forward指令

    forward指令用于将页面响应控制转发给另外的页面.既可以转发给静态的HTML页面,也可以转发到动态的JSP页面,或者转发到容器的Servlet. JSP的forward指令格式如下: 对于JSP1 ...

  6. java jsp 跳转_JSP页面跳转方法大全

    先来介绍一下在服务端JSP脚本中跳转页面的几种方法: 1. response.sendRedirct("跳转到页面"); 该方法通过修改HTTP协议的HEADER部分,对浏览器下达 ...

  7. JSP指令--Page指令

    page指令 page指令称为页面指令,用来定义JSP页面的全局属性,该配置会作用域整个页面. page指令的属性可以定义MIME类型.定义需要导入的包.错误页的指定等. page指令的语法格式如下: ...

  8. JSP userBean setProperty getProperty指令使用

    JSP userBean setProperty getProperty指令使用 javaBean的属性取决于get/set方法,而不是真实的属性名称. jsp文件: <%@ page lang ...

  9. 在SHTML中通过SSI指令实现文件动态包含

    文章地址: http://blog.csdn.net/5iasp/article/details/12992769 作者: javaboy2012 Email:yanek@163.com qq:    ...

最新文章

  1. Outlook2010 Bug 一则
  2. 证书格式pfx和cer的区别及转换
  3. java.lang.ClassNotFoundException
  4. django弹出对话框_Django实现简单网页弹出警告代码
  5. ASP.NET中PostBack和ViewState
  6. 【Pytorch】tensorboardX==》数据可视化
  7. python变量命名规则_Python教程第9篇:牢记Python变量命名5大规则
  8. 西密歇根大学计算机科学,西密歇根大学
  9. nor flash驱动编写步骤
  10. 自动刷新网页脚本_抢不到票?你离idol只差一个大麦抢票脚本。
  11. python好友管理系统
  12. android如何用mumu模拟器,如何安装网易MuMu模拟器 MuMu模拟器怎么用
  13. 2022年贵州省职业院校技能大赛中职组网络安全赛项规程
  14. IE下载文件无法弹出下载框
  15. RocketMQ-顺序消息Demo及实现原理分析
  16. mybatis mapperLocations配置失效
  17. 快来打造属于自己的天猫精灵
  18. 局域网常用的几种网络拓扑结构及其特点。
  19. 快速原型模型是什么?
  20. 新概念2 课文和单词(2)

热门文章

  1. 纪念宾得4000万象素的120数码相机645D推出两周年
  2. [转载] python下求语数总分和平均值_R和python语言如何求平均值,中位数和众数
  3. [转载] python indices_Python numpy.indices() 使用实例
  4. [转载] 用python写的一个简单的记事本
  5. Java 数组+循环升级篇
  6. android——数据库版本升/降级问题
  7. [转载]你呀,最大的问题就是太合群了
  8. Android学习笔记之AndroidManifest.xml文件解析(摘自皮狼的博客)
  9. 【转载】SQL 标量函数-----字符串函数 之二 去空格函数 LTRIM() 、RTRIM()
  10. _CentOS「linux」学习笔记11:crontab定时任务常用参数和基本语法