Tuesday, 5 February 2013

INTRODUCTION | J2EE Tutorial pdf

INTRODUCTION

JavaServer Pages, or JSPs, are a simple but powerful technology used most often to generate dynamic HTML on the server side. It is used to simplify the creation and management of the dynamic web pages by providing a more convenient authoring framework than servlet. JSPs are a direct extension of Java servlets designed to let the developer embed Java logic directly into a requested document. JSP pages combines static markup like HTML and XML, with special scripting tags. JSP pages resembles markup documents, but each JSP page is translated into a servlet the first time it is invoked. A JSP document must end with the extension .jsp.
JSP pages designed and developed less like programs and more like web pages. JSP pages are ideal when we need to display markup with embedded dynamic content. However, although generating HTML is much easier than with a servlet, JSP pages are less suited to handling processing logic. JSP pages can use JavaBeans to achieve a clean seperation of static content and the java code that produce dynamic web applications. This allows JSP pages to be created and maintained by designers with presentation skills, they do not need to know java.
While there is an overlap between their capabilities, think of servlets as controller objects, and JSP pages as view objects. Don’t think that we need to make a choice between using servlets and JSP pages in a web application; they are complementary technologies, and a complex web application will use both.
A simple JSP page that display current date in an HTML page would like this:
<%@ page import=”java.util.Date” %>
<html>
<body>
The current time is <%= (new Date()).toString() %>
</body>
</html>

Save this file as DateDemo.jsp in root directory like Webdemo and make request like
http://localhost:7001/Webdemo/DateDemo.jsp
The first time a JSP is loaded by the JSP container, the servlet code necessary to implement the JSP tags is automatically generated, compiled, and loaded into the servlet container. This occurs at translation time. It is important to note that this occurs only the first time a JSP page is requested. There will be a slow response the first time a JSP page is accessed, but on subsequent requests the previously compiled servlet simply processes the requests. This occurs at run time.
If we modify the source code for the JSP, it is automatically recompiled and reloaded the next time that page s requested.
This figure summaries the process from request to response:

There are three categories of JSP tags:--
1. Directives : These affects the overall structure of the servlet that results from translation, but produce no output themselves.
2. Scripting Elements: JSP scripting elements let we insert code into the servlet that will be generated from the JSP page.
3. Standard Actions : These are special tags available to affect the runtime behavior of the JSP page. JSP standard actions are predefined custom tags that can be used to encapsulate common actions easily. There are two types of JSP standard actions: the first type is related to JavaBean functionality, and the second type consists of all other standard actions.

No comments: