JSP (JAVA SERVER PROGRAM)
Introduction
JSP
stands for Java Server Pages. It is server side technology. It is used for
creating web applications. It is used to create dynamic web content. In this
JSP tags are used to insert JAVA code into HTML pages. It is an advanced
version of Servlet Technology. It is a Web based technology helps us to create
dynamic and platform independent web pages. In this, Java code can be inserted
in HTML/ XML pages or both. JSP is first converted into a servlet by the JSP
container before processing the client’s request.
JSP
technology is used to create web application just like Servlet technology. It
can be thought of as an extension to Servlet because it provides more
functionality than a servlet, such as expression language, JSTL, etc.
A JSP
page consists of HTML tags and JSP tags. The JSP pages are easier to maintain
than Servlet because we can separate designing and development. It provides
some additional features such as Expression Language, Custom Tags, etc.
Java
Server Pages (JSP) are a Java standard technology that enables you to write,
data driven pages for your applications. JSP is built on top of the Java servlet
specification. The two technologies typically work together, especially in
older Java web applications. From a coding perspective, the most obvious
difference between them is that with servlet you write Java code and then embed
client mark-up (like HTML) into that code, whereas with JSP you start with a
client-side script or mark-up, then embed JSP tags to connect your page to the
Java backend.
Advantages
of JSP over servlet
There are
many advantages of JSP over the servlet. They are as follows,
Extension
to servlet
Java servlets typically run on the HTTP protocol. HTTP is
an asymmetrical request-response protocol. It's always run on the server side
like Tomcat, JBoss etc.. Coming to File Extension it is
Normal Java File but when you clean and build/compile it should converted in
to. JSP technology is the
extension of Servlet technology.
Easy to
maintain
JSP can be easily managed because we can easily
separate our business logic with presentation logic. In Servlet technology, we
mix our business logic with the presentation logic.
Faster
Development: No need to recompile and redeploy
If JSP page is modified, we don't need to recompile
and redeploy the project. The Servlet code needs to be updated and recompiled
if we have to change the look and feel of the application.
Less code
than Servlet
In JSP,
we can use many tags such as action tags, JSTL, custom tags, etc. That reduces
the code. Moreover, we can use EL, implicit objects, etc.
Feature
of JSP
Coding in
JSP is easy: As
it is just adding JAVA code to HTML/XML. If you are a beginner, start with head
first servlet and jsp book. I believe you should understand
the servlet model before starting with jsp.
Reduction
in the length of the Code: In JSP we use action tags, custom tags etc. In other language we have
to write so many lines of code for a web application but, in JSP because of the
directives we don’t need to write so many lines of code.
Connection
to Database is easier: It is
easier to connect a website to the database and allows reading or writing data
easily to the database. The Connection of database we need to put one line of
code and some credentials so compare to other very easy to database is easier.
Make
Interactive websites: In this
we can create dynamic web pages which help user to interact in real time
environment. A JSP page looks similar to an HTML page, but a JSP page also has
Java code in it. We can put any regular Java Code in a JSP file using a
scriptlet tag which starts with <% and ends with %>. JSP pages are used
to develop dynamic responses.
Portable,
Powerful, flexible and easy to maintain: as these are browser and server independent. A
user interacting with JSP controls like textbox, button, dropdown list, a
checkbox can enter some information. Using JSP, it is easier to read this
information entered by the user and send it to the server.
No
Redeployment and No Re-Compilation: It is dynamic, secure and platform
independent, so no need to re-compile. The generated Java servlet file is
compiled into Java servlet class. The translation of the Java source page in
its implementation class can happen at any time between the deployment of JSP
page into the container and processing of the JSP page.
Extension
to the Servlet: As
it has all features of servlets, implicit objects and custom tags. Java servlets typically
run on the HTTP protocol. HTTP is an asymmetrical request-response protocol.
It's always run on the server side like Tomcat, JBoss etc. Coming to
File Extension it is Normal Java File but when you clean and
build/compile it should converted in to.
Steps for Execution of JSP are following:
Create HTML pages from where request will be sent
to the server. For example index.html. When the client sends the request
through a browser to a server. Then there is a page which accepts requests and
send to the dedicated server.
To handle to the request of user next is to create
JSP file. Example newfile.jsp
When the client requested to a server and for
handling requests, we use Jsp pages that will proceed the next process.
Create folder structure, when we use an IDE like
netbeans or eclipse after creating a project, It will automatically create html
pages that can be used for execution.
It also creates an xml page with the project. Like
content.xml. XML file role into the JSP is When you send the XML data
via HTTP, it makes sense to use JSP to handle
incoming and outgoing XML documents; for example, RSS
documents.
As an XML document is merely a
bunch of text, creating one through a JSP is much easier than
creating an HTML document.
After that you need to restart the server like
Tomcat/Glassfish is server stopped, and finally run the project file that you
have created.
Yes!
You did it your first JSP web application “HELLO WORLD!” printed on the web
browser that you connected with your IDE.
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Hello World - JSP</title>
</head>
<body>
<%= "Hello
World!" %>
</body>
</html>
Coming
Topics - JSP Programs and This will be fully
practical based content. Error and Bugs into creating and learning JAVA WEB
Application.
Comments
Post a Comment