Vous êtes sur la page 1sur 44

A Training Report On J2EE

A Training Report submitted in partial fulfillment of requirements for the degree of Bachelor of Engineering In Computer Science & Engineering

PREFACE
This report deals with programming in java and in particular advanced java. Each and every topic is kept in proper sequence with thorough planning. The details of every topic are explained as simply as possible. We hope that the project will find greater appreciation among different readers and teachers about its usefulness. It would be my sane opportunity to know if any mistakes have crept in to the script.

Acknowledgement
I acknowledge my gratitude and thank to all the well knowledge persons for giving me opportunity to avail all the best facilities available at HWELLET -PACKARD EDUCATION SERVICE through which I have gained knowledge thinking so as too just in the environment suitable for harmonic adjustment. I express my deep sense of gratitude to, Mr. Harish Kumar Advisor and Trainer for his valuable guidance and constant unfailing encouragement for completing the summer course. I would like to thank Mr. Shashikant Ranjan for their help and support for completing my summer course and project at HPES. Last but not the least; I thank my teacher, friends and my family members for their constant encouragement.

Abstract
The Java 2 Platform, Enterprise Edition (J2EE) defines the standard for developing multitier enterprise applications. The J2EE platform simplifies enterprise applications by basing them on standardized, modular components, by providing a complete set of services to those components, and by handling many details of application behavior automatically, without complex programming. The J2EE platform takes advantage of many features of the Java 2 Platform, Standard Edition (J2SE), such as "Write Once, Run Anywhere" portability, JDBC API for database access, CORBA technology for interaction with existing enterprise resources, and a security model that protects data even in internet applications. Building on this base, the Java 2 Platform, Enterprise Edition adds full support for Enterprise JavaBeans components, Java Servlets API, Java Server Pages and XML technology. The J2EE standard includes complete specifications and compliance tests to ensure portability of applications across the wide range of existing enterprise systems capable of supporting the J2EE platform. In addition, the J2EE specification now ensures Web services interoperability through support for the WS-I Basic Profile.

TABLE OF CONTENTS
1) Introduction..6 2) Basics of Core Java..7 a. Static Members: Static Methods & Static Variables10 b. Life Cycle of a Thread..11 c. Java - Exception Handling..12 d. Creating Strings....13 3) Enterprise Application Model15 4) Introduction to JDBC.16 a. JDBC API Overview16 b. Advantages of JDBC Technology...16 c. Key Features16 d. JDBC Architecture...17 e. Two-tier and Three-tier Models...19 f. JDBC Driver Type...20 5) Client Servlet Interaction....22 a. The Benefits of Servlets...23 b. Servlet Application Architecture.....24 c. Lifecycle of a servlet...24 d. Servlet sample code.26 6) JAVA SERVER PAGES...31 a. About JSP....31 b. The Problem with Servlets..32 c. Advantages Of JSP..32 d. The Anatomy of a JSP Page33 7) STRUTS.35 8) Training Project..37 9) Conclusion..42

1. INTRODUCTION
Today's enterprises gain competitive advantage by quickly developing and deploying custom applications that provide unique business services. Whether they're internal applications for employee productivity, or Internet applications for specialized customer or vendor services, quick development and deployment are key to success. Portability and scalability are also important for long term viability. Enterprise applications must scale from small working prototypes and test cases to complete 24x 7, enterprise-wide services, accessible by tens, hundreds, or even thousands of clients simultaneously. The J2EE specification also supports emerging Web Services technologies through inclusion of the WS-I Basic Profile. WS-I Basic Profile compliance means that the developers can build applications on the J2EE platform as Web services that interoperate with Web services from non-J2EE compliant environments. With simplicity, portability, scalability, and legacy integration, the J2EE platform is the platform for enterprise solutions.

2.BASICS OF CORE JAVA


Principles There were five primary goals in the creation of the Java language: It should be "simple, object oriented, and familiar". It should be "robust and secure". It should be "architecture neutral and portable". It should execute with "high performance". It should be "interpreted, threaded, and dynamic".

JAVA FEATURES

CONSTRUCTOS IN JAVA

A constructor is a special type of a method which is called automatically after the creation of object of its class. We mainly use the constructors to initialize the variables perform some specific type of tasks such as opening a file or starting a thread. There are some rules which should be followed during creating the constructors and they are : 1. The constructor cannot have a return type. 2. The name of the constructor should be the same as of its class. 3. The access specifier to the constructor must be public to create an object of the class. If the access specifier is private you are not able to create the object of the class. The basic declaration for constructor is : public class Constructordemo { Public constructor demo() { } } INHERITANCE

Inheritance is a powerful aspect of object-oriented programming that allows you to easily reuse code and extend the functionality of existing classes. Using this aspect of object-oriented programming, you can create a new class that inherits the functionality of an existing class. You can then extend the functions of the old class in ways that suit your current needs. In JAVA, inheritance is done by creating new classes that are extensions of other classes. The new class is known as a subclass. The original class is known as a super class. The subclass has all the attributes of the super class, and in addition has attributes that it defines itself. General form of inheritance-

Class subclass extend super-class

//body of the class

Types of Inheritance-Although there are 3 types of inheritance but CPP supports only following Types of Inheritance. These are followings Single Inheritance Multilevel Inheritance Hierarchical Inheritance

Single Inheritance-Inheritance with single Base and Derived class is called single inheritance. Following Symbol can represent it. Multilevel Inheritance The method of deriving a class from another drive class is known as multi level Inheritance.
A

Base class
B

Intermediate Base Class


C

Derived class

HIERARCHICAL INHERITANCE-

We have discussed so for have inheritance can be used to modify a class when it did not satisfy the requirements of a particular problem on hand. Additional members are added through inheritance to extend the capabilities of a class. Many programming problems can be coast into a hierarchy where certain features of one level are shared by many other below that level.

Static Members: Static Methods and Static Variables


There are situations in which the methods behavior does not depend on the state of an object. So, there will be no use of having an object when the method itself will not be instance specific. Let us consider another situation where in we want to keep a count of all the instances instantiated from a particular class. Suppose we declare an instance variable to do the job, it wont work. Its because the instance variables are initialized back to their default value each time a instance is created. So we need some variable which will be independent of the instances created. The answer to both the situations is to use the static modifiers, in other words static members. What exactly are Static Variable and Methods? Variables and methods marked static belong to the class rather than to any particular instance of the class. These can be used without having any instances of that class at all. Only the class is sufficient to invoke a static method or access a static variable. A static variable is shared by all the instances of that class i.e only one copy of the static variable is maintained. class Animal {

static int animalCount=0; public Animal() { animalCount+=1; } public static void main(String[] args) { new Animal(); new Animal(); new Animal(); System.out.println(The Number of Animals is: + animalCount); } } The output is The Number of Animals is 3.

THREADS In JAVA
Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution. A multithreading is a specialized form of multitasking. Multitasking threads require less overhead than multitasking processes. I need to define another term related to threads: process: A process consists of the memory space allocated by the operating system that can contain one or more threads. A thread cannot exist on its own; it must be a part of a process. A process remains running until all of the non-daemon threads are done executing. Multithreading enables you to write very efficient programs that make maximum use of the CPU, because idle time can be kept to a minimum.

Life Cycle of a Thread: A thread goes through various stages in its life cycle. For example, a thread is born, started, runs, and then dies. Following diagram shows complete life cycle of a thread.

Java - Exceptions Handling


An exception is a problem that arises during the execution of a program. An exception can occur for many different reasons, including the following:

A user has entered invalid data. A file that needs to be opened cannot be found. A network connection has been lost in the middle of communications, or the JVM has run out of memory.

Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner. To understand how exception handling works in Java, you need to understand the three categories of exceptions:

Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation. Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation. Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.

STRING IN JAVA
Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and manipulate strings. Creating Strings: The most direct way to create a string is to write: String greeting = "Hello world!"; Whenever it encounters a string literal in your code, the compiler creates a String object with its valuein this case, "Hello world!'. As with any other object, you can create String objects by using the new keyword and a constructor. The String class has eleven constructors that allow you to provide the initial value of the string using different sources, such as an array of characters: public class StringDemo{ public static void main(String args[]){ char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};

String helloString = new String(helloArray); System.out.println( helloString ); } } This would produce following result: Hello Note: The String class is immutable, so that once it is created a String object cannot be changed. If there is a necessity to make alot of modifications to Strings of characters then you should use String Buffer & String Builder Classes. String Length: Methods used to obtain information about an object are known as accessor methods. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object. After the following two lines of code have been executed, len equals 17: public class StringDemo{ public static void main(String args[]){ String palindrome = "Dot saw I was Tod"; int len = palindrome.length(); System.out.println( "String Length is : " + len ); } } This would produce following result: String Length is : 17

3. Enterprise Application Model of JAVA


The Enterprise Java Blueprints for the J2EE platform describe the J2EE application model and best practices for using the J2EE platform. Building on the J2SE platform, the J2EE application model provides a simplified approach to developing highly scalable and highly available internet or intranet based applications. Thanks to the J2EE application model, maybe the most interesting thing about J2EE applications is what they don't do. That is, various complexities inherent in enterprise applications -- transaction management, life-cycle management, resource pooling -- are built into the platform and provided automatically to the components it supports. Component and application developers are free to focus on specifics such as business logic and user interfaces. Another advantage of the J2EE platform is that the application model encapsulates the layers of functionality in specific types of components. Business logic is encapsulated in Enterprise JavaBeans (EJB) components. Client interaction can be presented through plain HTML web pages, through web pages powered by applets, Java Servlets, or Java Server Pages technology, or through stand-alone Java applications. Components communicate transparently using various standards: HTML, XML, HTTP, SSL, RMI, IIOP, and others. Reusable J2EE components mean competitive choices for enterprise developers and IT organizations. The J2EE platform enables them to assemble applications from a combination of standard, commercially available components and their own custom components. From general business application components to vertical market solutions, a range of standardized J2EE functionality is available off the shelf.

Figure 3.1 Enterprise Application Model

4. INTRODUCTION TO JDBC
The Java Database Connectivity (JDBC) API is the industry standard for databaseindependent connectivity between the Java programming language and a wide range of databases. SQL databases and other tabular data sources, such as spreadsheets or flat files. The JDBC API provides a call-level API for SQL-based database access. 4.1 JDBC API Overview The JDBC API makes it possible to do three things:

Establish a connection with a database or access any tabular data source Send SQL statements Process the results

4.2 Advantages of JDBC Technology 4.2.1 Leverage Existing Enterprise Data With JDBC technology, businesses are not locked in any proprietary architecture, and can continue to use their installed databases and access information easily -- even if it is stored on different database management systems. 4.2.2 Simplified Enterprise Development The combination of the Java API and the JDBC API makes application development easy and economical. JDBC hides the complexity of many data access tasks, doing most of the "heavy lifting"for the programmer behind the scenes. The JDBC API is simple to learn, easy to deploy, and inexpensive to maintain. 4.3 KEY FEATURES Full Access to Metadata The JDBC API provides metadata access that enables the development of sophisticated applications that need to understand the underlying facilities and capabilities of a specific database connection. No Installation A pure JDBC technology-based driver does not require special installation; it is automatically downloaded as part of the applet that makes the JDBC calls.

Database Connection Identified by URL JDBC technology exploits the advantages of Internet-standard URLs to identify database connections. The JDBC API includes an even better way to identify and connect to a data source, using a DataSource object, that makes code even more portable and easier to maintain.

4.4. JDBC ARCHITECTURE The JDBC API contains two major sets of interfaces: the first is the JDBC API for application writers, and the second is the lower-level JDBC driver API for driver writers. JDBC technology drivers fit into one of four categories. Applications and applets can access databases via the JDBC API using pure Java JDBC technologybased drivers, as shown in this figure:

Figure 4.1 JDBC Architecture1 Left side, Type 4: Direct-to-Database Pure Java Driver This style of driver converts JDBC calls into the network protocol used directly by DBMSs, allowing a direct call from the client machine to the DBMS server and providing a practical solution for intranet access. Right side, Type 3: Pure Java Driver for Database Middleware This style of driver translates JDBC calls into the middleware vendor's protocol, which is then translated to a DBMS protocol by a middleware server. The middleware provides connectivity to many different databases.

The graphic below illustrates JDBC connectivity using ODBC drivers and existing database client libraries.

Figure 4.2 JDBC Architecture 2 Left side, Type 1: JDBC-ODBC Bridge plus ODBC Driver This combination provides JDBC access via ODBC drivers. ODBC binary code -and in many cases, database client code -- must be loaded on each client machine that uses a JDBC-ODBC Bridge. Sun provides a JDBC-ODBC Bridge driver, which is appropriate for experimental use and for situations in which no other driver is available. Right side, Type 2: A native API partly Java technology-enabled driver This type of driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.

4.5 Two-tier and Three-tier Models The JDBC API supports both two-tier and three-tier models for database access. In the two-tier model, a Java applet or application talks directly to the database. This requires a JDBC driver that can communicate with the particular database management system being accessed. A user's SQL statements are delivered to the database, and the results of those statements are sent back to the user. The database may be located on another machine to which the user is connected via a network. This is referred to as a client/server configuration, with the user's machine as the client, and the machine housing the database as the server. The network can be an intranet, which, for example, connects employees within a corporation, or it can be the Internet.

In the three-tier model, commands are sent to a "middle tier" of services, which then send SQL statements to the database. The database processes the SQL statements and sends the results back to the middle tier, which then sends them to the user. MIS directors find the three-tier model very attractive because the middle tier makes it possible to maintain control over access and the kinds of updates that can be made to corporate data. Another advantage is that when there is a middle tier, the user can employ an easy-to-use higher-level API which is translated by the middle tier into the appropriate low-level calls. Finally, in many cases the three-tier architecture can provide performance advantages.

4.6 JDBC Driver Type The JDBC drivers that we are aware of at this time fit into one of four categories: 1. JDBC-ODBC bridge plus ODBC driver: The JavaSoft bridge product provides JDBC access via ODBC drivers. Note that ODBC binary code, and in many cases database client code, must be loaded on each client machine that uses this driver. As a result, this kind of driver is most appropriate on a corporate network where client installations are not a major problem, or for application server code written in Java in a three-tier architecture. 2. Native-API partly-Java driver: This kind of driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine. 3. JDBC-Net pure Java driver: This driver translates JDBC calls into a DBMSindependent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect its pure Java clients to many different databases. The specific protocol used depends on the vendor. 4. Native-protocol pure Java driver: This kind of driver converts JDBC calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. The following chart shows the four categories and their properties:

DRIVER CATEGORY ALL JAVA? NET PROTOCOL 1 - JDBC-OCBC Bridge 2 - Native API as basis 3 - JDBC-Net No No Yes Direct Direct Requires Connector Direct

4 - Native protocol as basis Yes

5.JAVA SERVLET TECHNOLOGY


Java Servlet technology provides a basic mechanism for generating dynamic Web content. Like all J2EE components, servlets run in a container implemented by the J2EE platform provider. The container manages a servlet's interaction with its client and provides a rich environment for the servlet to use to access various services based on Java technology. A servlet container implements all of the Java 2 Platform, Standard Edition APIs. This makes a variety of technologies based on the Java programming language available to servlets, including JDBC, Java Naming and Directory Interface, RMI, JavaBeans, and others. The container can also implement features that allow servlets to share information about a particular client and session, overcoming the obstacles generally presented by the stateless HTTP protocol. The flexibility of servlets is enabled through the servlet API, which implements a mechanism for more complex interaction with the requesting client than can CGI. Various servlet methods provide information to the servlet and allow it to respond. Because of the objectoriented programming model, items key to servlet behaviors are provided as objects with a welldefined API.

Figure 5.1 Client servlet interaction

5.1 The Benefits of Servlets When it first emerged, this great thing we call the Internet consisted of only static contents written using Hypertext Markup Language (HTML). At that time, anyone who could author HTML pages was considered an Internet expert. This did not last long, however. Soon dynamic web contents were made possible through the Common Gateway Interface (CGI) technology. CGI enables the web server to call an external program and pass HTTP request information to that external program to process the request. The response from the external program is then passed back to the web server, which forwards it to the client browser. CGI programs can be written in any language that can be called by the web server. Over the course of time, Perl became the most popular language to write CGI programs.

In the past, ASP and servlet/JSP have been the main technologies used in web application development. With the release of ASP.NET, it is not hard to predict that this technology will become the servlet/JSP's main competitor. ASP (and ASP.NET) and servlet/JSP each have their own fans, and it is not easy to predict which one will come out the winner. The most likely outcome is that neither will be an absolute winner that corners the market; instead the technologies will probably run head-to-head in the coming years. Servlet (and JSP) offers the following benefits that are not necessarily available in other technologies: Performance. The performance of servlets is superior to CGI because there is no process creation for each client request. Instead, each request is handled by the servlet container process. After a servlet is finished processing a request, it stays resident in memory, waiting for another request. Portability. Similar to other Java technologies, servlet applications are portable. You can move them to other operating systems without serious hassles. Rapid development cycle. As a Java technology, servlets have access to the rich Java library, which helps speed up the development process. Robustness. Servlets are managed by the Java Virtual Machine. As such, you don't need to worry about memory leak or garbage collection, which helps you write robust applications.

Widespread acceptance. Java is a widely accepted technology. This means that numerous vendors work on Java-based technologies. One of the advantages of this widespread acceptance is that you can easily find and purchase components that suit your needs, which saves precious development time.

5.2 Servlet Application Architecture A servlet is a Java class that can be loaded dynamically into and run by a special web server. This servlet-aware web server is called a servlet container, which also was called a servlet engine in the early days of the servlet technology. Servlets interact with clients via a request-response model based on HTTP. Because servlet technology works on top of HTTP, a servlet container must support HTTP as the protocol for client requests and server responses. However, a servlet container also can support similar protocols, such as HTTPS (HTTP over SSL) for secure transactions.

Figure 5.2 the Servlet Application Architecture 5.3 Lifecycle of a servlet The servlet lifecycle consists of the following steps: 1. The servlet class is loaded by the Web container during start-up. 2. The Web container calls the init() method. This method initializes the servlet and must be called before the servlet can service any requests. In the entire life of a servlet, the init() method is called only once. 3. After initialization, the servlet can service client requests. Each request is serviced in its own separate thread. The Web container calls the service() method of the servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request. The developer of the servlet must provide an

implementation for these methods. If a request for a method that is not implemented by the servlet is made, the method of the parent class is called, typically resulting in an error being returned to the requester. Finally, the Web container calls the destroy() method that takes the servlet out of service. The destroy() method, like init(), is called only once in the lifecycle of a servlet.

Figure 5.3 Servlet Lifecycle

5.4 Servlet sample code import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*;

public class TestingServlet extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>Servlet Testing</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("Welcome to the Servlet Testing Center"); out.println("</BODY>"); out.println("</HTML>"); }

The clientside browser will have the html page of code <html> <body bgcolor="white">

<h1>Good evening!</h1> Welcome to our site, open 24 hours a day. </body> </html>

The following table summarizes the core interfaces that are provided in this packageInterface Description 1. HttpServletRequest Enables servlets to read data from an Http request. 2. HttpServletResponse Enables servlets to write data to an Http response. 3. HttpSession Allows session data to be read and written.

The following table summarizes the core classes that are provided in this package. The most important of these is HttpServlet. Servlet developers typically extend this class in order to process Http Requests. Class Description 1. Cookie Allows state information to be stored on a client machine. 2. HttpServlet Provides methods to handle Httprequests and responses. 3. HttpSessionE Encapsulates a session changed event. vent

HttpServletRequests The HttpServletRequest interface is implemented by the server. It enables a servlet to obtain information about a client request. Extends the ServletRequest interface to provide request information for HTTP servlets. The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).

HttpServletResponse public interface HttpServletResponse extends ServletResponse Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. For example, it has methods to access HTTP headers and cookies. The servlet container creates an HttpServletResponse object and passes it as an argument to the servlet's service methods (doGet, doPost, etc). The HttpServletResponse interface is implemented by the server. It enables a servlet to formulate an HTTP response to a client. Several constants are defined. These correspond to the different status codes that can be assigned to an HTTP response. For example, SC_OK indicates that the HTTP request succeeded and SC_NOT_FOUND indicates that the requested resource is not available.

HTTPSession javax.servlet.http Interface HttpSession public interface HttpSession Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. The servlet container uses this interface to create a session between an HTTP client and an HTTP server. The session persists for a specified time period, across more than one connection or page request from the user. A session usually corresponds to one user, who may visit a site many times. The server can maintain a session in many ways such as using cookies or rewriting URLs. This interface allows servlets to

View and manipulate information about a session, such as the session identifier, creation time, and last accessed time

Bind objects to sessions, allowing user information to persist across multiple user connections

When an application stores an object in or removes an object from a session, the session checks whether the object implements HttpSessionBindingListening. If it does, the servlet notifies the object that it has been bound to or unbound from the session. Session information is scoped only to the current web application (ServletContext), so information stored in one context will not be directly visible in another.

Cookies A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is used for an origin website to send state information to a user's browser and for the browser to return the state information to the origin site. The state information can be used for authentication, identification of a user session, user's preferences, shopping cart contents, or anything else that can be accomplished through storing text data. Cookies are not software. They cannot be programmed, cannot carry viruses, and cannot install malware on the host computer . However, they can be used by spyware to track user's browsing activities a major privacy concern that prompted European and US law makers to take actions. Cookies could also be stolen by hackers to gain access to a victim's web account.

java.net Class HttpCookie java.lang.Object java.net.HttpCookie All Implemented Interfaces: Cloneable

An HttpCookie object represents an http cookie, which carries state information between server and user agent. Cookie is widely adopted to create stateful sessions.

6. JAVA SERVER PAGES


JavaServer Pages technology builds on Java Servlet technology to simplify the development of dynamic Web content. JSP supports a pagebased metaphor that conveniently separates dynamic and static Web content; the JSP page defines a static HTML template, with embedded calls to code written in the Java programming language to fill in dynamic portions of the page. JSP pages contain four kinds of elements, each with a specific role in the presentation of dynamic content. Text elements are normally content formatted through standard HTML or XML. These represent the static portion of the page. 1. Directives are instructions to the JSP processor. A JSP container processes these directives when compiling the page into an efficient executable form. 2. Tags invoke JavaBeans to generate dynamic content or perform other computations. Tag libraries are a powerful feature of JSPs used to encapsulate specific functionality invoked via HTML tags. These allow the JSP _language_ to be easily extended in a portable fashion. For example, tag libraries can be implemented to support embedded database queries for an application. 3. Scripting elements may be declarations, scriptlets, or expressions. Like tags, scripting elements can be used to perform computations to generate dynamic content. They are useful when standard tags are inappropriate or have not been defined. 4. The combination of these four elements makes it easy to generate Web pages for client browsers. Because JSP is based on servlets, users benefit from the application support and other features built into Web application containers. These include portability, access to common services, the ability to maintain state and clientaccess information via common APIs, and other servlet benefits. 6.1 About jsp Dynamic content. Unlike a plain HTML page, which contains static content that always remains the same, a JSP page can change its content based on any number of variable items, including the identity of the user, the user's browser type, information provided by the user, and selections made by the user. As you'll see later in the book, this functionality is key to web applications such as online shopping and employee directories, as well as for personalized and internationalized content. A JSP page contains standard markup language

elements, such as HTML tags, just like aregular web page. However, a JSP page also contains special JSP elements that allow the server to insert dynamic content in the page. JSP elements can be used for a variety of purposes, such as retrieving information from a database or registering user references. When a user asks for a JSP page, the server executes the JSP elements, merges the results with the static parts of the page, and sends the dynamically composed page back to the browser.

Figure 6.1 Generating Dynamic Content with JSP 6.2 The Problem with Servlets Thorough Java programming knowledge is needed to develop and maintain all aspects of the application, since the processing code and the HTML elements are lumped together. Changing the look and feel of the application, or adding support for a new type of client (such as a WML client), requires the servlet code to be updated and recompiled. It's hard to take advantage of web-page development tools when designing the application interface. If such tools are used to develop the web page layout, the generated HTML must then be manually embedded into the servlet code, a process which is time consuming, error prone, and extremely boring. 6.3 Advantages Of JSP 1. The JSP technology is platform independent, in its dynamic web pages, its web servers, and its underlying server components. That is, JSP pages perform perfectly without any hassle on any platform, run on any web server, and web-enabled application server. The JSP pages can be accessed from any web server. 2. The JSP technology emphasizes the use of reusable components. These components can be combined or manipulated towards developing more purposeful

components and page design. This definitely reduces development time apart from the At development time, JSPs are very different from Servlets, however, they are precompiled into Servlets at run time and executed by a JSP engine which is installed on a Web-enabled application server such as BEA Web Logic and IBM Web Sphere.

6.4 The Anatomy of a JSP Page A JSP page is simply a regular web page with JSP elements for generating the parts that differ for each request

Everything in the page that isn't a JSP element is called template text. Template text can be any text: HTML, WML, XML, or even plain text. Since HTML is by far the most common web-page language in use today, most of the descriptions and examples in this book use HTML, but keep in mind that JSP has no dependency on HTML; it can be used with any markup language. Template text is always passed straight through to the browser.

When a JSP page request is processed, the template text and dynamic content generated by the JSP elements are merged, and the result is sent as the response to the browser.

7. Struts
Web applications differ from conventional websites in that web applications can create a dynamic response. Many websites deliver only static pages. A web application can interact with databases and business logic engines to customize a response. One way to separate concerns in a software application is to use a Model-ViewController (MVC) architecture. The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code. The Struts framework is designed to help developers create web applications that utilize a MVC architecture. The framework provides three key components:

A "request" handler provided by the application developer that is mapped to a standard URI. A "response" handler that transfers control to another resource which completes the response. A tag library that helps developers create interactive form-based applications with server pages. 7.1 Design goals and overview

In a standard Java EE web application, the client will typically submit information to the server via a web form. The information is then either handed over to a Java Servlet that processes it, interacts with a database and produces an HTMLformatted response, or it is given to a JavaServer Pages (JSP) document that intermingles HTML and Java code to achieve the same result. Both approaches are often considered inadequate for large projects because they mix application logic with presentation and make maintenance difficult. The goal of Struts is to cleanly separate the model (application logic that interacts with a database) from the view (HTML pages presented to the client) and the controller (instance that passes information between view and model). Struts provides the controller (a servlet known as ActionServlet) and facilitates the writing of templates for the view or presentation layer (typically in JSP, but XML/XSLT and Velocity are also supported). The web application programmer is

responsible for writing the model code, and for creating a central configuration file struts-config.xml that binds together model, view and controller. Requests from the client are sent to the controller in the form of "Actions" defined in the configuration file; if the controller receives such a request it calls the corresponding Action class that interacts with the application-specific model code. The model code returns an "ActionForward", a string telling the controller what output page to send to the client. Information is passed between model and view in the form of special JavaBeans. A powerful custom tag library allows it to read and write the content of these beans from the presentation layer without the need for any embedded Java code. Struts also supports internationalization by web forms, and includes a template mechanism called "Tiles" that (for instance) allows the presentation layer to be composed from independent header, footer, and content components.

TRAINING PROJECT
ONLINE LIBRARY 1.Introduction:1.1 Purpose:The purpose of this application are as follows : The software is the automation of the library. It provides facilities to the ADMIN: Can enter details related to the particular book. Can provide membership to the members. Can read any information about any member. Can create, update and delete records of any member as per the requirements and as per the implementation plans. USER: Can find books without any membership. Can view and download the books after membership.

2 SCOPE :The different areas where we can use this applications are:Any Educational institute can make use of it by providing information about author , content of the available books. It can be used in offices and can modifications can easily be done as per the requirements.

3. TECHNOLOGY USED:Front end:- Servlets ,HTML,JAVA server pages Back end:- MYSQL, Apache tomcat server

4.ASSUMPTIONS:This application is used to convert the manual application into online application. Customized data is used in this application. User does not have right to enter any information about books.

5.OVERVIEW:Project is related to the library management which provides reading services to its members. Any person can become the member of the library by filling the prescribed form. They can view books and download them after becoming member of the library .

6) FUNCTIONALITY:Keeps the record of members.

FEASIBILITY STUDY In feasibility study we had undergone through various steps which are describe as under : 1. Identify the origin of the information at different level. 2. Identify the expectation of user from computerized system. 3. Analyze the drawback of existing system(manual) system.

WORKING OF PRESENT MANUAL SYSTEM The staffs of library are involved in the following tasks. 1. Membership process : Person has to fill membership form and they are provided with member id. PROPOSED SYSTEM Proposed system provide with following solutions:1. 2. 3. 4. It provides better and efficient service to the members. Reduce the workload of the employee. Faster retrieval of the information about the desired book. All details are available on a single click.

Future Scope FUTURE SCOPE OF APPLICATION : This application can be easily implemented under various situations. We can add new features as and when we require. Reusability is possible as and when require in this application. There is flexibility in all the modules

CONCLUSION
The pace of business is getting faster and faster, with a greater need to compete and sustain a market. In this age of ecommerce, ebusiness, etailing, and other e's, "traditional" system development just doesn't cut it anymore. Java Platform, Enterprise Edition or Java EE is a widely used platform for server programming in the Java programming language. TheJava platform (Enterprise Edition) differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular components running on an application server. The Java platform comes in three flavors: Standard Edition, Enterprise Edition and Macro Edition. The Enterprise Edition (J2EE) builds the Standard Edition & includes number of technologies, such as Enterprise JavaBeans(EJB), Servlet and JavaServer Pages, used for building enterprise server side- applications.

REFRENCES
[1] [2] [3] Enterprise JavaBeans, Third Edition , Richard Monson-Haefel JavaServer Pages, Hans Bergsten www.java.sun.com

Vous aimerez peut-être aussi