100 likes | 280 Views
Java Server Pages - Programming. <html<title>JSP code</title><body><% int sum = 0; for( int i = 0; i < 10; i )sum = i; out.print( "the sum is " sum );%></body></html>. JSP ? using classes. <html<title>JSP code</title><body><% java.util.Date d1 = new java.util.Date( ); out.print( d1 )
E N D
1. Java Server Pages - Programming Can have Java code between the tags
<%
// and
%>
2. Java Server Pages - Programming <html<title>JSP code</title><body>
<%
int sum = 0;
for( int i = 0; i < 10; i++)
sum += i;
out.print( "the sum is " + sum );
%>
</body></html>
3. JSP – using classes <html<title>JSP code</title><body>
<%
java.util.Date d1 = new java.util.Date( );
out.print( d1 );
%>
</body></html>
4. JSP – Using classes Instead of using the full path for a class
java.util.Date
We can import the class with a page directive
<%@ page import = "java.util.Date" %>
There can be any number of page directives within a JSP page
5. JSP – Directives JSP directives are enclosed between
<%@
and
%>
The 2 primary directives are
Page directive ? used primarily for import statements
Include directive ? used for including files
6. JSP – Using classes <html<title>JSP code</title><body>
<%@ page import = "java.util.Date" %>
<%
Date d1 = new Date( );
out.print( d1 );
%>
</body></html>
7. JSP – Using classes We can import more than one class
Use a comma separated list of classes that you want to import
<%@ page import = "java.util.Date,
java.util.StringTokenizer" %>
8. JSP – Using classes <html<title>JSP code</title><body>
<%@ page import = "java.util.Date,
java.util.StringTokenizer" %>
<%
Date d1 = new Date( );
out.print( d1 + "<br><br>");
StringTokenizer st = new StringTokenizer( "apple
pear nut kiwi" );
int num = st.countTokens( );
out.print( "There are " + num + " tokens” );
%>
</body></html>
9. JSP – Using classes We can use several page directives to import classes
<%@ page import = "java.util.Date" %>
<%@ page import =
"java.util.StringTokenizer " %>
10. JSP – Using classes We can use a bulk import statement in a page directive to import all the classes needed from a given package
<%@ page import = "java.util.*" %>