Everything you wanted to know about JSP Scripting Elements
Java
has emerged as a globally used and recommended web programming
language. JSP(Java Server Pages) has been amazingly utilized for
building web applications that cater to different types of industries
ranging from automotive industry, sports industry and health industry
to the consumer goods market. This article is dedicated to all those
Java programmers who aren't familiar with the scripting elements used
in JSP(Java Server Pages).
JSP Scripting Elements- What are they?
JSP scripting elements are basically the tags that allow you to insert Java code into the servlet that's being generated using the JSP page. The format used for defining these elements is as follows:
“<%....%>”
The dots denote the Java code. All the code written inside the tags is being processed by the JSP engine during the translation of JSP Page. Moreover, all the text or code that's been written in the JSP pages is being treated as the HTML content.
JSP Scripting Elements- What are the types?
There are five types of JSP scripting elements namely:
Directive tag
Comment tag
Expression tag
Scriptlet tag
Declaration tag
Now, lets cover each of the above mentioned JSP scripting elements one by one:
1. JSP Directive tag
This
is a form of JSP scripting element that's being used for providing
special instructions to the web container during the page translation
process. The syntax used for defining the JSP directive tag is: <%@
directives %>. Also, the three types of JSP directive tags
include: page, include and taglib.
2. Comment tag
JSP Comment tag is used for documenting the code. With this tag, you can note some of the most crucial parts of the JSP page and make them easier to maintain. Below is the detailed code snippet that illustrates the JSP comment used inside a JSP Page:
<%-- This is a JSP comment --%>
<%--
This is a JSP comment can span
in multiple lines
--%>
3. Expression tag
The Expression scripting element includes a Java expression that returns a particular value which is further written to the HTML Page. This scripting element can include any expression that adheres to the guidelines of the Java Language Specification. The syntax used for the Expression tag is:
<%=
Java expression %>Java expression is being converted into a string and inserted into the
page. Here's the syntax that's being used by XML authors as an
alternative for JSP expressions:Java
Expression
4.JSP Scriptlet tagJSP Scriptlet tag is yet another brilliant JSP Scripting element that
allows you to write the Java code in your JSP page. The syntax used
for including this tag is as shown below:<% Java code %> Here's an example of the JSP Scriptlet tag:
Sciptlet tag page <% out.println("This is Scriptlet tag");%>
5.Declaration tagA declaration tag comprises of either methods or variables. For
example, you can choose to include static constants within a
declaration tag. The JSP code that you write using a declaration tag
is converted into a class definition, with all the scriptlets being
placed inside the single method of the defined class.
SummarySo,that's it for now from my side. Hope you'd have enjoyed reading this
article. I'm sure the details about different JSP scripting elements
would aid you in executing your Java projects in the right way.
About the Author :
Celin Smith is a web developer as well as technical content writer, who works at Xicom Technologies Ltd., a leading software development company. Serving Xicom, a leading Java Web Development Company , Celin basically writes about web & mobile apps, and technologies including Java, ASP.NET, PHP, etc.
Post Your Ad Here

Comments