JavaBeat
Struts Tutorials | Hibernate Tutorials | JSP Tutorials | Servlet Tutorials | EJB Tutorials | Struts Resources | Spring Resources | Hibernate Resources
JSP Home Articles Resources Tutorials FAQs Forums  

1. Getting familiar with your JSP server

2. Your first JSP

3. Adding dynamic content via expressions

4. Scriptlets

5. Mixing Scriptlets and HTML

6. Directives

7. Declarations

8. Tags

9. Sessions

10. Beans and Forms Processing

11. Tag Libraries

12. Form Editing

13. Log-in pages

14. SQL

15. Sending Email

16. Further learning

JSP Directives

We have been fully qualifying the java.util.Date in the examples in the previous sections.  Perhaps you wondered why we don't just import java.util.*;

It is possible to use "import" statements in JSPs, but the syntax is a little different from normal Java.  Try the following example:

<%@ page import="java.util.*" %>
<HTML>
<BODY>
<%
    System.out.println( "Evaluating date now" );
    Date date = new Date();
%>
Hello!  The time is now <%= date %>
</BODY>
</HTML>
The first line in the above example is called a "directive".  A JSP "directive" starts with <%@ characters.

This one is a "page directive".  The page directive can contain the list of all imported packages.  To import more than one item, separate the package names by commas, e.g.

<%@ page import="java.util.*,java.text.*" %>
There are a number of JSP directives, besides the page directive.  Besides the page directives, the other most useful directives are include and taglib.  We will be covering taglib separately.

The include directive is used to physically include the contents of another file.  The included file can be HTML or JSP or anything else -- the result is as if the original JSP file actually contained the included text.  To see this directive in action, create a new JSP

<HTML>
<BODY>
Going to include hello.jsp...<BR>
<%@ include file="hello.jsp" %>
</BODY>
</HTML>
View this JSP in your browser, and you will see your original hello.jsp get included in the new JSP. Exercise:  Modify all your earlier exercises to import the java.util packages.


Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
Describe the lifecycle of a receiver application in order to receive a message?
Messages are not successful until they have been acknowledged. What are the types of acknowledgments?
What happens to messages if a transaction is rolled back?
What is the Role of the JMS Provider?
What is JMS administered object ?

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat