Wednesday, 31 August 2011

JSP and Servlet tutorial for beginners - #2 - What is JSP?

I hope you have the necessary software [IDE and Servers] installed in your machine, if not, please take a look at this post to know how to install IDE and other stuffs and also do install them.

What is JSP?
  • JSP stands for Java Server Pages and it was designed by Sun microsystem to compete with ASP and PHP in earlier 2000.
  • Java Server Pages (JSP) technology is the Java platform technology for delivering DYNAMIC content to web clients in a portable, secure and well-defined way.
  • JSP enables the developers to put java code into jsp, this makes the development process very simple and easy.
  • Since JSP runs on Java Server, we can run it on any platform.
  • JSP - Presentation layer which displays the actual output after the java statements in JSP are processed by the server container.
Intro to JSP tags:
  • As we know that JSP is a scripting language which has its own tags to include Java content into it. Let’s have a brief look at the JSP tags.
  • There are four types of JSP tags available, they are:
    • Directives:  In directive tag we can import packages, define error handling pages, handle session information of the JSP page.
    • Declarations: In declaration tag, we can provide the definition of  the functions and variables that are going to be used in the JSP.
    • Scriptlets: In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine. [JSP engine converts JSP into Servlet]
    • Expresssions: We can use this tag to output any data on the generated page. These data are automatically converted to string and printed on the output stream[commonly browser].
Code snippet
Following are the sample code snippet:
>>Directives<<
<%@page contentType="text/html" import="java.util.Date" %>

>>Declarations<<
<%!String retString(){
return "Hello World";
}
%>
>>Scriptlets<<
<%out.print("Welcome to JSP");%>
>>Expressions<<
<%="Today's date: "+ new Date() %>

>>Comments<<
<%-- I am sample JSP comment--%>
<%-- JSP Engine will not process me!! :) --%>

Download

Download Project



as

0 comments: