2 Minutes To Code (β Version)

JSP - 2 minute tutorial

Write your first jsp

The overview section of this tutorial says that jsp is html friendly. Let's see how friendly.

In a jsp, you can write html code itself (i.e. head, body, div, span, table etc). Besides thse, you can even write plain java code to create content dynamically. This is what makes it so much more convenient than java servlets, where you have to write lots of messy out.println("<body>Good morining !</body>") to create content for webpage.

So, now let's our first jsp. We will not use any java code in it, so what we have in our hands is 6 lines of plain old html tags shown in the section 'Source code of first.jsp' below. Just save it in a file with name first.jsp, put it in a war file named myApp.war , deploy the war file in the web-server of your choice.

Let's test our jsp now. Open your web browser and hit the url :
(You may need to change the ip, port and war file name to match the ones you are using.)

The web browser will show the response shown in the section 'Rendering first.jsp in browser' below.

Time to pat your back, you are a jsp developer now.

Source code of first.jsp

		Hi friends.<br>
		Current server time is Sat Aug 11 12:57:34 GMT 2012

Rendering first.jsp in browser

What's the point of the above example when the same thing could have been achieved by putting the 4 lines of code in a .html file.

Jeez...take it easy tiger/tigress ... it was just to make you comfortable with a new framework.

Let's pick up the other bells and whistles that jsp specification provides in the next few pages on our way to becoming true jsp ninja.