JSP Elements Overview

A JSP page can be said to be divided into two types of contents, which are template text and JSP elements. Template text is any non-java lines like html, comments, javascript, css etc. that are directly sent to the client without any processing. Java code is embedded into JSP pages using scripting elements and these elements will be processed and not directly rendered to the output like template text.

 

JSP elements can be mainly divided into 3 categories:

  • Directive element

    • Most often use these to communicate global information to your page.

  • Scripting elements

    • To incorporate dynamic information or execute presentation logic.

  • Actions

    • These use XML-style tags for the inclusion of dynamic data.

 

Directives

Directives are elements that provide the JSP translator with directions on how it should treat the JSP page being translated.

Our simplejsp from previous demo had the below page directive in it:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

            pageEncoding="ISO-8859-1"%>

A directive starts with <%@ followed by the directive name (e.g. page), some attributes with values (e.g. language="java") and ends with %>

Important directives are page, include and taglib directives.

 

Scripting

With the scripting support you can write your own java logic in a JSP page.

There are mainly two forms of scripting in a JSP

  1. Newer Expression Language (EL)

  2. Traditional Scripting

Traditional language-based scripting elements in a JSP are further divided into:

  1. Expressions (starts with <%= and ends with %>)

  2. Scriptlets (starts with <% and ends with %>

  3. Declarations (starts with <%! and ends with %>

  4. Comments (starts with <%-- and ends with %>

 

Expression Language (EL)

Expression language (EL) allows us to write scriptless JSP components by replacing the JSP expression scripting element.

EL expressions are represented in code as ${expression}.

EL only replaces expressions and we can also replace other traditional scripting elements with tag libraries, servlets or helper classes, allowing us to better divide tasks between java developers and html.xml developers.

EL can also be used along with standard actions and custom tags.

 

Actions

Actions are XML elements that encapsulate functionality on a JSP page. Programmers can create them and they can be used by the nonprogrammer to introduce dynamic behavior to a JSP page without having any knowledge of Java programming language. For those, non-programmers these will like a new html or xml tag element.

There are two forms of action elements:

  1. standard

  2. custom.

Standard actions are used for the same purpose as Java language-based scripting. Most things that we can achieve with scripting elements are achievable with other standard actions also. Difference between standard and custom actions are that you can rely on any J2EE-compliant JSP container to provide support for all the standard actions defined in the JSP spec. Custom actions will have to be imported manually.

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quizzes (17) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (1) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)