![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e1058. Generating Dynamic Content on a JSP PageThe primary method for generating dynamic content on a JSP page is through the use of JSP expressions. A JSP expression is essentially a Java expression that is automatically converted to aString and
written to the output stream. Here are some examples of JSP expressions:
The value of Pi is: <%= Math.PI %> A random number between 1 and 100 is: <%= (int)(Math.random()*100)+1 %> The value of the "p" request paramter is: <%= request.getParameter("p") %> Today is: <%= new java.text.SimpleDateFormat("EEEE").format(new java.util.Date()) %>Dynamic content can also be generated from a scriptlet by using out to write to the output stream. Here are some examples:
<% if (Math.random() > .5) { out.println("<b>You win!</b>"); } else { out.println("Sorry, you lose. Try again."); } %>
e1059. Implementing Conditional Content on a JSP Page e1060. Handling Unhandled Exceptions in a JSP Page
© 2002 Addison-Wesley. |