Page Directive JSP

Page directive dalam JSP yang dimaksudkan adalah memasukkan komponen lain diluar suatu page jsp. Page directive terdiri atas 2 macam yaitu untuk melakukan import terhadapat komponent- komponen java diluar page JSP dan untuk melakukan render page jsp lain kedalam suatu jsp.Berikut contoh penggunaan page directive jsp.
HelloWorld.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World JSP</title>
</head>
<body>
<%
	String a = "JSP USER";
	out.println("<h3>Hello World "+a+"<h3>");
%>
</body>
</html>

PageDirective.jsp

<%@ page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Page Directive</title>
</head>
<body>
	<%@include file="HelloWorld.jsp" %>
	<br /> the time is <%=new Date() %>
</html>

output

Tagged: , , ,

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: