J2EE
Introduction
●

Q. What is J2EE ?
Java platform to developing enterprise web
application
Basic Architecture
Description
●

J2EE architecture : 3 tier
–

Client Tier ( Web tier)
●

–

Business Tier
●

–

The Presentation layer on t...
Java Web Components
●

Servlet

●

Jsp ( Java Server Pages )

●

Jstl (Jsp Standard Tag Library)

●

Jsf ( Java Server Fac...
Servlet
●

Extends web server's functionality

●

Respond to Request from client

●

Used to generate dynamic response

●
...
Functioning of Servlet
●

●

●

Process or Store data that was submitted by
HTML forms
Provide dynamic content such as the...
Packages (imports) for Servlet
●

java.io.*;
–

●

javax.servlet
–

●

Input and Output package (eg. Out.println)
Contains...
●

javax.servlet.http.HttpServletRequest;

●

javax.servlet.http.HttpServletRespons
Servlet Skeleton
●

Imports

●

Public classname extends HttpServlet
–

Public void init()
●

–

Public void Service()
●

...
Lifecycle
●

Loaded and Instantiated

●

Initialization

●

Servicing the request

●

Destroying the request
●

Loaded and instantiated
–

●

Container loads servlet during startup or when the
request is made. After loading the ser...
●

Servicing the request
–

After successful initialization , servlet will be
available to serve the request. Servlet crea...
●

Destroying the servlet
–

If the servlet is no longer needed , the servlet
container calls the destroy() method.

–

Li...
JSP (Java Server Pages)
●

Jsp is a component which generates dynamic
contents

●

Jsp is a server-side technology

●

Ext...
JSP Components
●

Declaration tag

●

Scriptlet tag

●

Expression tag

●

Directive tag

●

Action tag
●

Declaration tag:
–

Declaration is used to declare and define java
variables and methods inside your jsp

–

They are i...
Declaration Example :
<html>
<body>
<%! int value = 10; %>
Hello World!<%= value %>
</body>
</html>
●

Scriptlet tag:
–

Scriptlets are block of java code

–

You can write any number of java code inside your
jsp using scr...
Scriptlet Example :
<html>
<body>
Hello World!
<%
out.println("Helloworld");
%>
</body>
</html>
●

Expression tag:
–

The code placed inside expression tag is printed
(output) , so there is no need to write out.println...
Expression Example :
<html>
<body>
<%! int value = 10; %>
Hello World! <%= value %>
</body>
</html>
●

Directive tag:
–

Jsp directive provide directions and instructions to
the container , how to handle certain jsp
proces...
–

Page directive
●

●
●

Page directive is used to provide information about the
page
Example : <%@page language="java" %...
–

Include directive
●
●
●

Include is used to include a jsp file in the jsp page
Example : <%@ include file="/header.jsp"...
–

Taglib directive
●

●
●

Taglib directive is used to use the custom tags in the
jsp page ( custom tags allow us to defi...
●

Action tag:
–

The action tag basically are used to control the
flow between pages and to use Java Beans
–

Some of the action tags are
●
●
●
●
●
●
●
●

Jsp:forward
Jsp:include
Jsp:useBean
Jsp:setProperty
Jsp:getPropery
Jsp:plu...
Upcoming SlideShare
Loading in …5
×

servlets and jsp

370 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
370
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

servlets and jsp

  1. 1. J2EE
  2. 2. Introduction ● Q. What is J2EE ? Java platform to developing enterprise web application
  3. 3. Basic Architecture
  4. 4. Description ● J2EE architecture : 3 tier – Client Tier ( Web tier) ● – Business Tier ● – The Presentation layer on the client side includes j2ee componenets such as jsp,jsf etc Components containing business logic of the application such as Enterprise Beans. Database Tier ● This tier contains the persistence API of the application so as to talk to database
  5. 5. Java Web Components ● Servlet ● Jsp ( Java Server Pages ) ● Jstl (Jsp Standard Tag Library) ● Jsf ( Java Server Faces )
  6. 6. Servlet ● Extends web server's functionality ● Respond to Request from client ● Used to generate dynamic response ● Usually responses in HTML or Xml format ● Most often used with HTTP protocol
  7. 7. Functioning of Servlet ● ● ● Process or Store data that was submitted by HTML forms Provide dynamic content such as the result of a database query Manage State information (in case of stateless HTTP protocol)
  8. 8. Packages (imports) for Servlet ● java.io.*; – ● javax.servlet – ● Input and Output package (eg. Out.println) Contains interaction logic between web container and servlet javax.servlet.http – Contains Http specific logic
  9. 9. ● javax.servlet.http.HttpServletRequest; ● javax.servlet.http.HttpServletRespons
  10. 10. Servlet Skeleton ● Imports ● Public classname extends HttpServlet – Public void init() ● – Public void Service() ● – { /* Initialization goes here */ } {/* Business logic goes here */ } Public void destroy() ● {/* Free resources here */}
  11. 11. Lifecycle ● Loaded and Instantiated ● Initialization ● Servicing the request ● Destroying the request
  12. 12. ● Loaded and instantiated – ● Container loads servlet during startup or when the request is made. After loading the servlet , the container creates the instance of the servlet when the first request come for service , Initialization – After creating the instance the container calls init() method. The init method is called only once in servlets lifetime. Initialization logic goes here
  13. 13. ● Servicing the request – After successful initialization , servlet will be available to serve the request. Servlet creates separate thread for each request – Service() method is called to serve the request in short service method contains the business logic
  14. 14. ● Destroying the servlet – If the servlet is no longer needed , the servlet container calls the destroy() method. – Like the init() method destroy() method also get called only once in servlet's lifetime – Destroy() method releases all the resources which were acquired previously
  15. 15. JSP (Java Server Pages) ● Jsp is a component which generates dynamic contents ● Jsp is a server-side technology ● Extension : .jsp ● Jsp usually consist of two components – Static Data ● – Can be expressed in any text based format such as HTML JSP elements ● Jsp tags , which can generates dynamic contents
  16. 16. JSP Components ● Declaration tag ● Scriptlet tag ● Expression tag ● Directive tag ● Action tag
  17. 17. ● Declaration tag: – Declaration is used to declare and define java variables and methods inside your jsp – They are initialized when the jsp page is initialized – The scope of the declared variables or methods is within the jsp page – Syntax : <%! int a = 10; %>
  18. 18. Declaration Example : <html> <body> <%! int value = 10; %> Hello World!<%= value %> </body> </html>
  19. 19. ● Scriptlet tag: – Scriptlets are block of java code – You can write any number of java code inside your jsp using scriptlet – Syntax : <% ( Java Code ) %>
  20. 20. Scriptlet Example : <html> <body> Hello World! <% out.println("Helloworld"); %> </body> </html>
  21. 21. ● Expression tag: – The code placed inside expression tag is printed (output) , so there is no need to write out.println() – Mainly used to print values of variables and methods – Syntax : <%= (variable or method) %>
  22. 22. Expression Example : <html> <body> <%! int value = 10; %> Hello World! <%= value %> </body> </html>
  23. 23. ● Directive tag: – Jsp directive provide directions and instructions to the container , how to handle certain jsp processing – There are 3 types of directives ● ● ● Page directive Include directive Taglib directive
  24. 24. – Page directive ● ● ● Page directive is used to provide information about the page Example : <%@page language="java" %> Here language is an attribute of the page directive
  25. 25. – Include directive ● ● ● Include is used to include a jsp file in the jsp page Example : <%@ include file="/header.jsp" %> File is an attribute which specifies which file need to include
  26. 26. – Taglib directive ● ● ● Taglib directive is used to use the custom tags in the jsp page ( custom tags allow us to define our own tags ) Example : <%@ taglib uri="tlds/taglib.tld" prefix="mytag" %>
  27. 27. ● Action tag: – The action tag basically are used to control the flow between pages and to use Java Beans
  28. 28. – Some of the action tags are ● ● ● ● ● ● ● ● Jsp:forward Jsp:include Jsp:useBean Jsp:setProperty Jsp:getPropery Jsp:plugin Jsp:param Jsp:fallback

×