72-A, 1st floor 100 feet road,Vadapalani, Chennai-600026, Tel-044 43069973,Mob-9500041042 Email:info@softorix.com Website: www.softorix.com J2EE What is JEE and where JEE being used? Java Platform, Enterprise Edition (Java EE) is the industry, open standard for developing portable, robust, scalable and secure server-side Java applications
It is suite of specifications for APIs, a distributed computing architecture, and definitions for packaging of distributable components for deployment
Java EE provides various technologies to develop the client side presentation, server side presentation and the server side business logic Java Application, Java Applet, HTML for client side presentation Servlets/JSP for server side presentation Enterprise Java Beans (EJB) for server side business logic J2EE Application Server - JBoss Powerful, very configurable, an Open Source Application Server.
Full-fledged Java EE Application Server which supports Java EE 1.4 specification
It gets all the advantages of Java Programming language, as it is Java based
Comes in 3 configurations: all, default, minimal Cont. Vendors can implement Java EE standard (well defined specification) to develop Java EE Application Servers
Java EE Application Servers provide system services in a well defined and open standard manner Red Hat JBoss Oracle BEA WebLogic IBM WebSphere
JEE Architecture Working of a Web Application Internet uses Client/Server technology for its working
The world wide web uses the Browser as the client software and Web Server as the server software
The user types the required URL in the browser
The IP Address of the Server is found from the URL
The Web Server will be listening in that Server (machine) at Port No 80
The browser connects to Port No 80 of the specified Server
Based on the request, the Web Server will deliver the appropriate page to the browser
HTTP Protocol Hyper Text Transfer Protocol or HTTP is the protocol used by the world wide web
According to the HTTP protocol, the client should send a Request to the server in a special format
Based on the Request, the server will send back a Response, which again is in a special format
HTTP Request : The following is the request generated by Internet Explorer when the URL was http://www.yahoo.com HTTP Response : The server processes the request and sends a Response
Static Page Vs Dynamic Page From the web, we get static pages as well as dynamic pages Static Page Dynamic Page Can be created and stored in web server in advance as HTML file. Can NOT be created and stored in web server in advance as HTML file. Static page does not change with user and/or time. Dynamic page changes as per the user and/or time. For delivery of static page, all we require at server side, HTML files in Web Server. For delivery of dynamic page, apart from Web Server, we require program to generate dynamic content. The software component that runs the server side program to generate the dynamic content is known as the Web Container Generation of Dynamic Pages 1. User Submits Form and resultant URL: http://abcbooks.co.in/eshop/ PurchaseItem?iname=Floppy+Disc&qty=12 Web Server abcbooks.co.in 202.68.33.49 2. Send HTTP Request for eshop/PurchaseItem with params http://abcbooks.co.in/e Online Shopping Bill Floppy Disc Goods once sold will not be taken back Happy Shopping Price: Rs. 240/- 3. Forwards the request to a Server Side Program for execution 4. Compose HTML output Online Shopping Item Name Floppy Disc Quantity 12 Submit http://abcbooks.co.in/e 5. Send HTTP Response which contains the HTML output of the request The Internet Server Side Program Servlets Servlet was introduced by Sun Microsystems as an effective way to generate dynamic content for web applications
Servlet is a Java program that is executed at the server
The server associates the Servlet with a URL
When the URL is invoked, the Servlet is executed
Servlet works in a request/response model Accepts a request Carries out the request and sends a response, which can be in HTML format Thus, Servlets can be used to generate dynamic pages Servlet Container For executing the programs in the server side, the web server requires the help of a web container
Servlets are executed by a Servlet Container
Tomcat is a Servlet Container that is popularly used
JBoss App Server has Tomcat embedded in it as the default Servlet Container The Container should be able to execute any Servlet
This requirement calls for a standard interface for all the Servlets
A class should implement the interface called Servlet in the package javax.servlet to become a Servlet
Servlets The important methods of the Servlet interface are as follows init service destroy
JSP - JavaServer Pages JSP is a technology developed by Sun Microsystems for coding the presentation layer of an enterprise application A JSP file is very similar to an HTML file Unlike HTML files, JSP files will contain some Java code also, within <% %> elements The JSP file will have .jsp extension The server associates the JSP with a URL When the URL is invoked, the JSP is executed
JSP Just like a ServletContainer is required for executing a Servlet, a JSP Container is required for executing a JSP
Tomcat is a very popular JSP container
When a client requests for a JSP, the JSP container sends the HTML tags as-is to the browser
The code between <% and %> will be compiled, executed and the output will be sent to the browser
JSP Can be used to code presentation logic Can be used to generate dynamic pages Is as simple as HTML, even web designers can use it easily
Example <%@ page language="java"%> <html> <head> <title>Add number program in JSP</title> </head> <body> <% int a=5; int b=2; int result=a+b; out.print("Additon of a and b :"+result); %> </body> </html> JSP Servlet Suitable for coding the presentation layer of an enterprise application Servlet Bits of Java code embedded in HTML Created and maintained by web designers Suitable for coding the business layer of an enterprise application Created and maintained by Java programmers Bits of HTML embedded in Java code JSP On first invocation, the Web Container Creates the equivalent Servlet from the JSP
Compiles the Servlet into Java Implementation Class
Executes that Servlet Class
On subsequent invocations, the Web Container
Checks whether the JSP has changed since the equivalent Servlet has been created If not, executes the Servlet again If changed, recreates Servlet, compiles and executes it
Tags in JSP Tags in JSP can be categorized as
Comments: embedded in <%!-- --%>
Scripting elements Scriptlets embedded in <% %> Expression: elements embedded in <%= %> Methods and class variables: embedded in <%! %> JSP Lifecycle The code that should be executed only once when the JSP is invoked for the first time can be coded in a method jspInit()
The jspInit() method will be executed only once per JSP, not per request
This method contains code for initializing the JSP
The code that should be executed only once when the JSP is unloaded from the memory can be coded in a method jspDestroy()
Implicit Objects They are made available by the Web Container, in _jspService() method Can be used within the Java code (scriptlets) in a JSP, without ever having to declare them, and hence the name, implicit objects They are defined either in Servlet API / in JSP API
IMPLICIT OBJECTS Classes defined in API out JspWriter request HTTPServletRequest response HTTPServletResponse session HTTPSession application ServletContext config ServletConfig exception * JspException (* Only available in error pages) Directive Elements Directive elements provide information to the JSP container about the page
JSP can contain three types of directives page include taglib
The page directive has the following form
The include directive can be used to include the contents of some other file in a JSP
The contents can be static (HTML Page) or dynamic (Another JSP)
<%@ page attributes %> <%@ include file = "../Header.html" %> Action Elements Action elements are tags that affect the runtime behavior of a JSP
Action elements are also known as Standard Actions
Some common standard actions are <jsp:forward> <jsp:include> <jsp:useBean> <jsp:setProperty> <jsp:getProperty> <jsp:param> <jsp:forward page = url /> <jsp:include page = url /> <jsp:useBean id = "myWishObj" class = somePack.WishBean /> The above tag is equivalent to the following Java code
somePack.WishBean myWishObj = new somePack.WishBean(); Java EE - APIs Java EE comes with lots of APIs. Some of the APIs are already covered in Advanced Java: JDBC RMI
Some other important APIs in Java EE are: JNDI JMS
Enterprise Java Bean (EJB) EJB is a server-side software component that can be deployed in a distributed multi-tier environment. Used to build distributed components EJBs implement the Business Logic of the enterprise application. In a banking application, for example, the enterprise beans might implement the business logic in methods called deposit and withdraw By invoking these methods, clients can access the banking services provided by the application
An EJB is a Plain Old Java Object (POJO) which implements Plain Old Java Interfaces (POJI) EJBs are NOT same as JavaBeans An EJB is written using the EJB API (javax.ejb.*) and is deployed into an EJB container.
The client of an EJB could be - a servlet - a JSP - a stand alone Java application - an applet - a SOAP based web service client - another EJB
EJB technology is based on two other technologies: Java RMI-IIOP and JNDI.
Types of EJB There are 3 types of EJBs depending on the design requirement: Session Bean stateless and stateful Entity Bean Container persistent and Bean persistent Message Driven Bean - A Message-driven Bean is considered as a JMS MessageListener, which processes JMS messages asynchronously
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to process the request:
<PRE>
TEXT http://www.scribd.com/titlecleaner?title=Presentation1.ppt HTTP/1.1
User-Agent: Opera/9.80 (Windows NT 6.1; U; en) Presto/2.10.229 Version/11.61
Host: www.scribd.com
Accept-Language: en-US,en;q=0.9
Accept-Encoding: gzip, deflate
Proxy-Authorization: Basic a3VtYXJzYW5kaXA6OTE5OTQwOTgxNXJz
Referer: http://www.scribd.com/upload-document?archive_doc=76043007&metadata=%7B%22page%22%3A%22read%22%2C%22platform%22%3A%22web%22%2C%22action%22%3A%22down