JSP Elements & Directives Flashcards
scriptlet
- scriptlet tag allows to write Java code into JSP
- it can contain any number of Java statements, variable or method declarations, or expressions that are valid in the page scripting language
JSP declaration tag
< %! Inside this tag we can initialize our variables, methods, and classes % >
open angled bracket percent exclamation mart + codes + percent closed angled bracket
- it is for declaring variables, methods and classes
syntax of Scriptlet tag
< % java code % >
- it allows to write/insert Java code into JSP file
syntax of JSP expression
< %= expression % >
- it evaluates the expression placed in it
- it allows creating expressions like arithmetic and logical
syntax of JSP comments
< % – JSP comments – % >
- is used to comment in JSP and ignored by the JSP container
What are the 3 scripting elements in JSP?
- scripting tag
- expression tag
- declaration tag
JSP Directives
< %@ directive attribute=”value” % >
- directions and instructions to the container, telling it how to handle certain aspects of the JSP processing
- a JSP directive affects the overall structure of the servlet class
3 types of JSP directives
- Page directive
- Include directive
- Taglib directive
Page directive
< % @page .. % >
- it provides attributes that get applied to the entire JSP page
- by convention, it is coded at the top of the JSP page
import attribute
- the most used attribute in page directive
- similar to the import statement, it tells the container to import other java classes, interfaces, enums, etc.
Include directive
< % include file = “filename” % >
- it is used to include a file during the translation phase
- it tells the container to merge the content of other external files with the current JSP
- you may code the include directives anywhere on your JSP page
- very useful in creating templates with the user views and breaking the pages into header & footer and sidebar actions