Open In App

What is JSP Page?

A JSP page is a normal web page with JSP elements for generating the parts of the web page that differ for each request. A simple JSP web page that contains the JSP elements and template text. Everything on the page that is not a JSP element is called Template text. Template text can be any text, i.e., HTML, XML, WML or even plain text.JSP has no dependency on HTML, it can be used with any markup language. Template text is always passed straight to the browser.

JSP Elements

There are three types of JSP elements present:    



  1. Directive
  2. Action
  3. Scripting

New Components were added in JSP 2.0 as an Expression Language(EL) and let’s call this a fourth element type, even though it’s a bit different than the other three.

1. Directive Elements

page:   <%@ page … %>



Attributes that we can use are:  

In all the above “import” attribute can be used many times.

Example:

<%@ page language="java" import="java.util.*,java.sql.*" info="Contact page"
           extends="com.rajkumar.User" contextType="text/html" isELIgnored="false"
       isThreadSafe="false" session="false" %>

include: <%@ include … %>

Example:

<%@ include file="filename" %>
<%@ include file="header.jsp" %>

taglib:  <%@ taglib … %>

Declares a tag library, containing custom actions, that is used on the page for using Spring Frameworks

Template Text

Template data refers to the static HTML or XML content of the JSP.  Aside from the usual substitutions, such as those based on quoting and escape sequences, the template data is written verbatim as part of the JSP response.

2. Action Tag/Element

JSP Action tags or Elements are used to perform some specific tasks. The action tags are used to control the flow between pages and to use Java Beans. There are many JSP action tags.

3. Scripting Element

Scriptlet elements must be written within the <% … %> tags.The Scriptlet tag allows writing Java code statements within the JSP page.The tag is responsible for  implementing the functionality of “_jspService()” by scripting the java code.The JSP engine will process any code written within the pair of <%  and %> tags and any other code is treated as plain text while translating the JSP page. There are three main subdivisions of Scripting Elements in Java Server Pages.

Article Tags :