如何使用操作在 JSP 中?


plugin 操作用於將 Java 元件插入 JSP 頁面。它確定瀏覽器的型別,並根據需要插入 <object><embed> 標籤。

如果所需的外掛不存在,它將下載外掛,然後執行 Java 元件。Java 元件可以是 Applet 或 JavaBean。

plugin 操作具有幾個屬性,這些屬性對應於用於格式化 Java 元件的常用 HTML 標籤。<param> 元素也可用於向 Applet 或 Bean 傳送引數。

以下是使用 plugin 操作的典型語法:

<jsp:plugin type = "applet" codebase = "dirname" code = "MyApplet.class" width = "60" height = "80">
   <jsp:param name = "fontcolor" value = "red" />
   <jsp:param name = "background" value = "black" />

   <jsp:fallback>
      Unable to initialize Java Plugin
   </jsp:fallback>
</jsp:plugin>

如果您有興趣,可以使用一些 applet 嘗試此操作。一個新的元素,<fallback> 元素,可以用來指定在元件失敗時傳送給使用者的錯誤字串。

The <jsp:element> Action
The <jsp:attribute> Action
The <jsp:body> Action

<jsp:element>,<jsp:attribute><jsp:body> 操作用於動態定義 XML 元素。動態這個詞很重要,因為它意味著 XML 元素可以在請求時生成,而不是在編譯時靜態生成。

以下是一個動態定義 XML 元素的簡單示例:

<%@page language = "java" contentType = "text/html"%>
<html xmlns = "http://www.w3c.org/1999/xhtml" xmlns:jsp = "http://java.sun.com/JSP/Page">
   <head><title>Generate XML Element</title></head>
   <body>
      <jsp:element name = "xmlElement">
         <jsp:attribute name = "xmlElementAttr">
            Value for the attribute
         </jsp:attribute>
         <jsp:body>
           Body for XML element
        </jsp:body>
     </jsp:element>
   </body>
</html>

這將在執行時生成以下 HTML 程式碼:

<html xmlns = "http://www.w3c.org/1999/xhtml" xmlns:jsp = "http://java.sun.com/JSP/Page">
   <head><title>Generate XML Element</title></head>
   <body>
      <xmlElement xmlElementAttr = "Value for the attribute">
         Body for XML element
      </xmlElement>
   </body>
</html>

更新於:2019-07-30

908 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.