Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

JSP and Directives page,include,taglib (Java)

JSP and Directives page,include,taglib (Java) สำหรับ Directives ในภาษา JSP เป็นรูปแบบคำสั่งที่สั่งให้ JSP ทำการเรียกใช้งาน Resource ที่อ้างถึง หรือกำหนดคุณสมบัติของ Page ซึ่งแบ่งออกเป็นหลัก ๆ 3 ส่วน คือ page include และ taglib โดยในการใช้งาน Directive จะขึ้นด้วยเครื่องหมาย <% @ ตามด้วย Tags ของ Directive ลองมาดูรูปแแบบการใช้งานเช่น

<%@ page import="java.util.Date" %> <%@ include file="banner.jsp" %> <%@ page errorPage="errorPage.jsp" %> <%@ page session="true" %> <%@ taglib uri="uri" prefix="prefixOfTag" > <%@ page import="java.util.*,java.text.*" %> <%@ page language="java" %> <%@ page contentType="text/html" %> <%@ page contentType="text/html;char-set=windows-874" %> <%@ page buffer="32kb" %> <%@ page autoFlush="false" %> <%@ page isThreadSafe="false" %>

รูปแบบการใช้งาน Directives ต่าง ๆ ซึ่งคำสั่งต่าง ๆ เหล่านี้จะมีความจำเป็นในการเขียน JSP อย่างแน่นอน ซึ่งแต่ล่ะตัวใช้งานอย่างไร ลองมาดูตัวอย่างคร่าว ๆ

Example 1 ตัวอย่างการใช้ page import ในการเรียกใช้งาน Package และ Class

index.jsp
<%@ page import="java.util.*" %>
<html>
<head>
	<title>ThaiCreate.Com JSP Tutorial</title>
</head>
<body>
	<%
	    Date date = new Date();
	%>
	Hello!  The time is now <%= date %>
</body>
</html>

Output

JSP and Directives



Example 2 ตัวอย่างการใช้ page import ในการเรียกใช้งาน Package และ Class

index.jsp
<%@ page import="java.util.ArrayList" %>
<%@ page session="true" %> 
<html>
<head>
	<title>ThaiCreate.Com JSP Tutorial</title>
</head>
<body>
	<%
	
	    ArrayList<String> myArrList = new ArrayList<String>();
	    myArrList.add("Belgium");
	    myArrList.add("France");
	    myArrList.add("Italy");
	    myArrList.add("Germany");
    
		for (int i = 0; i < myArrList.size(); i++) {
		%>
			<%= myArrList.get(i) %> <br>
		<%
		}
	%>
</body>
</html>

Output

JSP and Directives



Example 3 ตัวอย่างการใช้ page include ในการเรียกใช่งานไฟล์ jsp

JSP and Directives

โครงสร้างไฟล์ banner.jsp และ index.jsp ซึ่งไฟล์ index.jsp จะเรียกไฟล์ banner.jsp มาแสดงผล

banner.jsp
<table width="400px">
<tr>
<td bgcolor="red">
	<center><h1>Banner ThaiCreate.Com</h1></center>
</td>
<tr>
</table>

index.jsp
<html>
<head>
	<title>ThaiCreate.Com JSP Tutorial</title>
</head>
<body>
	<%@ include file="banner.jsp" %>
	
	Welcome to ThaiCreate.Com
</body>
</html>

Output

JSP and Directives






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-05-26 11:46:30 / 2013-08-20 21:29:23
  Download : Download  JSP and Directives page,include,taglib  (Java)
 Sponsored Links / Related

 
JSP and Eclipse IDE Create Web Project and Run Project
Rating :

 
JSP and Netbeans IDE Create Web Project and Run Project
Rating :

 
ในการเขียน JSP (Java) ใช้เครื่องมืออะไรดี ระหว่าง Eclipse IDE กับ Netbeans IDE
Rating :

 
JSP and Scriptlets คืออะไร ทำไมจะต้องใช้ Scriptlets ในการเขียน JSP
Rating :

 
JSP and Basic Webpage , Basic HTML and JSP Scriptlets (Java)
Rating :

 
JSP and Block Variable and Declaration Variable for JSP (Java)
Rating :

 
JSP and Comment Code Single Line and Multiple Line (Java)
Rating :

 
JSP and Tag XML Style (Java)
Rating :

 
JSP and Import Package Library and Using Libraries (Java)
Rating :

 
JSP and Include JSP file / Include page (Java)
Rating :

 
JSP and errorPage / isErrorPage (Java)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่