JSP and Servlets

by E-Computer Concepts March 30, 2020 at 7:23 am

Introduction

JavaServer Pages (JSP) are actually, text files that combine standard HTML and new scripting tags. JSPs look like HTML, but they get complied into Java Servlets the first time they are invoked. Java servlets are a key component of server-side Java development.

A servlet is a small pluggable extension to a server that enhances the server’s functionality. Servlets allow developers to extend and customize any Java-enabled Server – a web server, a mail server, an application server or any custom server.

JSP

JavaServer pages are on the whole, text files that combine standard HTML and new scripting tags. JSPs look like HTML, but they get compiled into Java Servlets the first time they are invoked.

JSP
JSP

The resulting servlet is a combination of the HTML from the JSP file and embedded dynamic content specified by the new tags. That is not to say that JSPs must contain HTML. Some of them will contain only java code; this is particularly useful when the JSP is reasonable for a particular task like maintaining application flow.

What is needed to write JSP based web application?

As you will come to know in a short time, programming with JSP will need a thorough knowledge of how servlets are written and executed as the code segments inserted in a JSP are mostly Servlet code.

To write a JSP code you require an editor. To test the JSPs you need a JSP engine. So this material considers the Java Web Server to the JSP engine. This is the same web server that we considered for testing the Java Servlets.

How does JSP look ?

Consider the HelloWorld.jsp below

<HTML>
<HEAD>
<META NAME="GENERATOR" Content ="Microsoft Visual Studio 7.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<center><h1>
<% out.printIn("Hello World"); %>
</h1><center>
<BODY>
</HTML>

As you can see a JSP page looks almost like a simple HTML file. In the above HelloWorld.jsp line number 8 is the one accounting for the dynamic content. All of the rest lines are static HTML content. If you observe line 8 carefully, you can notice that the written code resembles servlet code in some way.

Servlets

The rise of server-side Java applications is one of the latest and most exciting trends in Java programming. The Java language was originally intended for use in small, embedded devices. Java’s potentially as a server-side development platform had been sadly overlooked until recently.

Businesses in particular have been quick to recognize Java’s potential on the server-side. Java is inherently suited for large client/server applications. The cross platform nature of Java is extremely useful for organizations that have a heterogeneous collection of servers running various flavors of the UNIX and Windows operating systems. Java’s modern, object-oriented, memory-protected design allows developers to cut development cycles and increase reliability.

In addition, Java’s built-in support for networking and enterprise APIs provides access to legacy data, easing the transition from older client/server system.

Java servlets are a key component of server-side Java development. A servlet is a small pluggable extension to a server that enhances the server’s functionality. Servlets allow developers to extend and customize any Java-enabled Server – a webs server, a mall server, a mail server, an application server or any custom server.

Add Comment