You are on page 1of 7

Server Side Programming-1

1.What is J2EE?

Explain.

Java Enterprise Edition (Java EE) is a technology from Sun Microsystems to build distributed applications which simplifies complexity, allows faster design, development and deployment of Web applications. It also reduces cost, manages multitier Web application developments. The capabilities and functionality of each release of J2EE is agreed on through the platform is then

Java Community Process (JCP). The

implemented by application server vendors and producers,such as BEA, IBM, iPlanet, ATG, SilverStream, and JBOSS. This means that J2EE

developers have a choice of product vendors fromwhom to select, based on quality, support, or ease of use. The ability tosubmit technologies through the JCP, and the two-way flow that exists between the main Java vendors and the open-source community ensures that a constant stream of new ideas helps to move J2EE forward.In this unit, we are going to study the concepts of Java 2 Enterprise Edition (J2EE), its

applications, and architecture. In addition, we have

a look at the standard HTTP protocol used for communication either on a network or on the Web, and the usage of Web Servers in application development. Java EE uses multi-tiered, distributed architecture. It provides a standard for developing and deploying multi-layered and distributed Web applications. Normally, thin-client multi-tiered applications are hard to write because they involve many lines of intricate code to handle transaction and state management, multi-threading, resource pooling, and other complex low-level details The component-based and platform-independent Java EE architecture makes Java EE applications easy to write because business logic is organized into reusable components and the Java EE server provides underlying services in the form of a container for every component type. Web - Tier Architecture Web - Tier allows to divide application in different layers so that the applications becomes more readable, easy to trouble shoot, improves performance and interdependency on view, business logic and database. HTTP Hyper Text Transfer Protocol (HTTP) is a client-server

protocol used for data exchange on Internet. Http request can be handled by GET, POST, and HEADER etc methods. GET is a default method. WebServer Web server handles only Http protocol whereas Application server provides exposes business logic for client applications through various protocols. Every request of application server goes through Web server only. It handles static pages, images like, GIG, JPG, etc. Web servers are: Apache Tomcat, Microsoft IIS, lighttpd, and Google GWS etc. Application Server Application Server serves business logic. It can handle any kinds of protocol.

Examples: BEA Weblogic, IBM Webshpere, JonAS (Java Open Application Server), Sun Java System Application Server (Sun Microsystems), Sun GlassFish Enterprise Server, (Red Hat) JBoss, JRun(Adobe), Apache Geronimo (Apache Software Foundation) etc. 2.What is Servlet Life Cycle? Explain in detail.

The lifecycle of a Servlet begins when it is loaded into Server memory and ends when the Servlet is

terminated or reloaded. The Servlet interface defines the following three lifecycle methods, called by the Servlet container: a) public void init(ServletConfig config) throws ServletException b) public abstract void service (ServletRequest req, ServletResponse res) throws ServletException, IOException c)public void destroy() When we start up a Servlet container, it searches for a set of configuration files, i.e. web.xml called as Deployment Descriptors (DD) that describes all the web applications. Deployment Descriptor is one per web application that includes an entry for each of the Servlets it uses. First of all the Servlet container creates an instance of the given Servlet class using the method Class.forName(className).newInstance() and then loads the Servlet in the memory. The init () method - Servlet Initialization After instantiation of Servlet, many times, a Servlet needs to perform some kind of initialization before handling the request, Servlet calls init() method. It

is responsible for performing initialization required by the Servlet, which can include setting up resources that the Servlet will require to process requests, such as database connections. The init() will be called only once per Servlet. Syntax: public void init(ServletConfig config) throws ServletException The container passes the object of ServletConfig interface, which contains all the initialization parameters, declared in deployment descriptor. This is quite important in order to ensure the reusability of aServlet. For example, if you are going to make a database connection in the Servlet instead of hardcoding the username/password and the database URL in the Servlet, you can use the init() method that allows you to specify them in the deployment descriptor. These values can be changed as needed without affecting the Servlet code. web.xml having initialized parameter <init-param> <param-name>driver</param-name> <param-value>org.gjt.mm.mysql.Driver</param-

value> </init -param> <init -param> <param-name>user</param-name> <param-value>root</param-value> </init -param> <init -param> <param-name>password</param-name> <param-value>root</param-value> </ init -param> The service() method: Each incoming service request to the Servlet is handled by service() method. It accepts two parameters: ServletRequest: The incoming request stream encapsulated in a ServletRequest object, and

//////////////////////////////////////////////////////// For full Version visit http://smudeassignments.blogspot.com/

This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send

a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. //////////////////////////////////////////////////////

You might also like