Figure 2-12. Generating JavaServer Pages Expressions and Directives

Figure 2-12. Generating JavaServer Pages Expressions and Directives In addition to scriptlets, JavaServer Pages allow the use of expressions and directives. A JSP expression begins with <%=and ends with %>. Any Java expression between the two tags is evaluated, the result is converted to a String, and the text is included directly in the page. This technique eliminates the clutter of an out.println()call. For example, <%= foo %>includes the value of the foovariable. A JSP directive begins with <%@and ends with %>. A directive allows a JSP page to control certain aspects of its workhorse servlet. Directives can be used to have the workhorse servlet set its content type, import a package, extend a different superclass, implement an interface, and handle either GET or POST requests. A directive can even specify the use of a non-Java scripting language. In between the directive tags certain key variables can be assigned values using the following syntax: <%@ varname = "value" %> Here are the six variables you can set: content_type Specifies the content type of the generated page. For example: <%@ content_type = "text/plain" %> The default content type is “text/html”. import Specifies a list of classes the servlet should import. Multiple classes can be given in a comma-separated list or given through multiple importdirectives. For example: <%@ import = "java.io.*,java.util.Hashtable" %> extends Specifies the superclass the servlet should extend. For example:
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services

Comments are closed.