Home > Java and Web > JSP Directives – Include Directive

JSP Directives – Include Directive

September 2, 2013 Leave a comment Go to comments

Include directive digunakan untuk menyisipkan berkas text ke dalam page JSP.

Syntax

<%@ include file="URL"%>

Contoh penggunaan include

Nama file : Header.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h5>This is Header</h5>
</body>
</html>

Nama file : Footer.jsp

<%@page import="java.util.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h5>This is Footer Today : <%= new Date()%></h5>
</body>
</html>

Nama file : index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@include file="Header.jsp" %>
<%
out.println("<h5>");
out.println("This Is Body");
out.println("</h5>");
%>
<%@ include file="Footer.jsp" %>
</body>
</html>

 

Print screen result:

Result

Result

 

Semoga bermanfaat.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: