Introduction to Java Server Pages (JSP)
Java Server Pages (JSPs) technology is to present web contents to users. In addition to presentation of a page to user, jsp technology offers many things. This is the list of things that JSP offers -
- Integration of static and dynamic contents
- Request and response model of servlet
- Expression language
- Mechanism to reuse jsp components
- Mechanism to use Java beans for data transfer
Let us understand the jsp and write the first jsp.
Jsp page contains two types of contents -
- Static Contents: Static contents include static html/xml, images, client side javascript etc. Static contents are called static because, there is no change in these components with each page load. E.g. there may be a logo image in a page, this image does not get changed frequently. Hence it can be called as static content.
- Dynamic Contents: These contents may get changed with every page load. Basically, we are looking at the data part of a page presented to user. Mostly application web front ends display data sent by the server. Server side processing generates data through middle tier or server side processing. Server sends this data to the client i.e. the web browser. Web browser displays this data along with the static contents. Such contents are called as dynamic contents.
Now we know that when a jsp page is rendered in a client browser to a user, then it has to get some data from the server. So the jsp page should maintain some details, which will make the connection with the server possible. We will look at these details in next few articles. Let us take a simple jps page and try to present it to client.
There are two ways of writing a jsp, using html or using xml. Let us not go into complexities of learning xml. We write a jsp page in html.
<HTML>
<HEAD>
<TITLE>First JSP</TITLE>
</HEAD>
<BODY>
<h1><%out.print("Hello, This is my First JSP.");%></h1>
</BODY>
</HTML>
Let us differentiate the static and dynamic contents. Here everything other than the code enclosed with <%….%> is static. The static content are written in html, hence most of the browser parse these and present to you.
The dynamic contents need some special handling. This handling is provided by jsp engine. Jsp engine is something that parses the dynamic contents also, and converts it into the browser recognizable from i.e. html here. If you look at the converted page (by doing view source of the page shown in browser), everything is static and browser recognizable.
<HTML>
<HEAD>
<TITLE>First JSP</TITLE>
</HEAD>
<BODY>
<h1>Hello, This is my First JSP.</h1>
</BODY>
</HTML>
Finally, this is how our jsp when deployed on a server will look like. (You can use Eclipse dynamic project for this. Copy this jsp to WebContent directory, and deploy it on tomcat).










Leave your response!