Page 106 - การโปรแกรมเว็บ
P. 106

7-94 การโปรแกรมเว็บ
       กอ่ นอน่ื ตอ้ งระบไุ วท้ ส่ี ว่ นแรกของ JSP page กอ่ นวา่ จะใช้ tag library เพมิ่ เตมิ โดยใชค้ �ำสง่ั ดงั น้ี

(ในท่นี ีจ้ ะไม่กลา่ วถึงรายละเอียด)

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

       ตัวอย่างที่ 7.37 การใช้ <sql: setDataSource>
 MyJSP15_JSTL_setdatasource.jsp

     1 <%@page contentType="text/html" pageEncoding="UTF-8"%>
    2 <!DOCTYPE html>
    3 <%@taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%>
    4 <%@taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix = "sql"%>
    5 <html>
    6 	 <head>
    7 		 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    8 		 <title>JSP Page</title>
    9 	 </head>
    10 	 <body>
    11 		 <sql:setDataSource var = "snapshot" driver = "com.mysql.jdbc.Driver"
    12 		 url = "jdbc:mysql://localhost/TEST"
    13 		 user = "user_id" password = "mypassword"/>
    14 		 <sql:query dataSource = "${snapshot}" sql = "..." var = "result" />
    15 	 </body>
    16 </html>

ท่ีมา: 	https://www.tutorialspoint.com/jsp/jstl_sql_setdatasource_tag.htm

       ค�ำอธิบาย
            บรรทัดที่ 1-2 เป็นแท็ก Directive การก�ำหนดค่าของแอตทริบิวต์ jsp เพื่อก�ำหนด

ค่าการแสดงผลภาษาในเพจน้นั วา่ มีการแปลงรหสั อักษรเปน็ แบบใด
            บรรทัดที่ 3 การเรยี กใช้งาน Library JSTL
            บรรทัดที่ 4 การเรยี กใชง้ าน Library JSTL sql
            บรรทัดท่ี 5 ค�ำส่ังแท็กเปิดของไฟล์ html
   101   102   103   104   105   106   107   108   109   110   111