May 2001
Intermediate to advanced
1088 pages
30h 13m
English
The earlier example in Listing 14.4 could have been written in a much more compact way that determined the time of day first and printed out its greeting near the end of the file. Listing 14.6 shows a much more compact version.
<HTML>
<BODY>
<%
java.util.Calendar currTime = new java.util.GregorianCalendar();
String timeOfDay = "";
if (currTime.get(currTime.HOUR_OF_DAY) < 12)
{
timeOfDay = "Morning!";
}
else if (currTime.get(currTime.HOUR_OF_DAY) < 18)
{
timeOfDay = "Afternoon!";
}
else
{
timeOfDay = "Evening!";
}
%>
Good <% out.write(timeOfDay); %>
</BODY>
</HTML>
|
As you can see, Listing 14.6 is much easier to read because it doesn't jump back and forth between ...
Read now
Unlock full access