JSP directives provide directions and instructions to the container, telling it how to handle certain aspects of JSP processing. In this tutorial, we will study the page directive and include directive in JSP.
<%@ page import="java.util.*,java.text.*" %> <% Date date = new Date(); // if we do not use the page import directive, // we will write: java.util.Date date = new java.util.Date(); %> Hello! The time is now <%= date %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%! private double toDouble(String value) { return(Double.parseDouble(value)); } %> <%= toDouble("two") %>
<%@ page errorPage="error.jsp" %>
Page content is here <%@ include file="footer.jsp" %>
<%@ page import="java.util.Date" %> <%-- The following become fields in each servlet that results from a JSP page that includes this file. --%> <%! private int accessCount = 0; private Date accessDate = new Date(); private String accessHost = "<I>No previous access</I>"; %> <P> <HR> This page © 2008 <A HREF="http//www.my-company.com/">my-company.com</A>. This page has been accessed <%= ++accessCount %> times since server reboot. It was most recently accessed from <%= accessHost %> at <%= accessDate %>. <% accessHost = request.getRemoteHost(); %> <% accessDate = new Date(); %>