Action plugin ใช้สำหรับแทรกคอมโพเนนต์ Java ลงในหน้า JSP มันกำหนดประเภทเบราว์เซอร์และแทรกแท็ก <object> หรือ <embed> ตามที่จำเป็น
หากปลั๊กอินที่ต้องการไม่มีอยู่ มันจะดาวน์โหลดปลั๊กอินแล้วจึงดำเนินการคอมโพเนนต์ Java คอมโพเนนต์ Java สามารถเป็น Applet หรือ JavaBean ได้
Action plugin มีแอตทริบิวต์หลายตัวที่สอดคล้องกับแท็ก HTML ทั่วไปที่ใช้จัดรูปแบบคอมโพเนนต์ Java องค์ประกอบ <param> ยังสามารถใช้เพื่อส่งพารามิเตอร์ไปยัง Applet หรือ Bean ได้
ไวยากรณ์ทั่วไปของการใช้ Action 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>
คุณสามารถลอง Action นี้ด้วย Applet บางตัวหากสนใจ องค์ประกอบใหม่ <fallback> สามารถใช้เพื่อระบุสตริงข้อผิดพลาดที่จะส่งให้ผู้ใช้ในกรณีที่คอมโพเนนต์ล้มเหลว
The <jsp:element> Action The <jsp:attribute> Action The <jsp:body> Action
<jsp:element>, <jsp:attribute> และ <jsp:body> Actions ใช้เพื่อกำหนดองค์ประกอบ XML แบบไดนามิก คำว่า "ไดนามิก" สำคัญ เพราะหมายความว่าองค์ประกอบ XML สามารถสร้างขึ้นได้ในขณะรันไทม์ แทนที่จะเป็นแบบคงที่ตอนคอมไพล์
ตัวอย่างง่ายสำหรับกำหนดองค์ประกอบ XML แบบไดนามิก -
<%@page language = "java" contentType = "text/html"%> <html xmlns = "https://www.w3c.org/1999/xhtml" xmlns:jsp = "https://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 = "https://www.w3c.org/1999/xhtml" xmlns:jsp = "https://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>