This action might not be possible to undo. Are you sure you want to continue?
Article Home> Articles > JSP > Architecture / Design JSP and J2EE Design Tutorial After going through the JSP tutorial,you should now be able to write simple web based applications. This tutorial goes further by presenting different architectue and design options. It defines a stable and versatile environment for web applications
04/28/09 03:49:21 Summary of how JSP works
JSP enables the dynamic generation of web pages,similar to ASP.NET and PHP.
When someone visits a JSP page,the HTML web page is generated and sent back to the visitor. Below you can see the construction of a basic web page. The HTML source code on the side shows the output The date today is.
In order for a static web page to show today's date,it would need to be edited every day and uploaded to the web server. This is very time consuming for such a simple task. This is where the dynamic generation of web pages is used.
In the JSP above,special syntax is used to signify that the current date needs to be displayed. You have probably seen this in the JSP tutorial already. This special syntax is processed on the web server and sent back to the visitor as a normal (html) web page.
04/28/09 03:49:21 Introduction to terms; JSP,J2EE,EJB and Ser Today,more and more companies want to develop distributed transactional applications for the enterprise and leverage the speed,security,and reliability of server-side technology. Before presenting a way of designing such a system,several key terms need to be understood. What is J2EE? The Java 2 Platform Enterprise Edition (J2EE) technology provides a component-based approach to the design,development,assembly,and deployment of enterprise applications. The J2EE platform provides the ability to reuse components in different applications. J2EE is made up of 13 different technologies including JavaServer Pages,Servlets,Enterprise JavaBeans,JavaMail,XML,JavaMail and many more.
The main technologies that we will be using are: • JavaServer Pages (JSP). • Servlets • EJB
What are JavaServer Pages? JavaServer Pages (JSP) is a technology based on the Java language and enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side development. JSP files are HTML files with special Tags containing Java source code that provide the dynamic content.
What are Servlets? A Servlet is a Java class that provides special server side service. To display any information on a web page,HTML code is embedded in “println” statements. JSP technology is an extension of Servlets. It is easier to generate GUI pages using JSP because a web page editor (such as Macromedia DreamWeaver ) can be used to create simple pages.
What are Enterprise JavaBeans? Enterprise JavaBeans (EJB) provides a component specification for the development of scalable and secure middleware components. The EJB Server handles security and transaction management details so developers can focus on implementing the business logic.
What are the benefits of using J2EE? There are several reasons for using the J2EE set of technologies: Extensibility and maintainability Division of work along skill lines Scalability,portability,availability. Code reuse. Interoperability – legacy integration Focus on implementing business logic Separation of code with differing rates of change.
04/28/09 03:49:21 Simple J2EE application Simple J2EE application In our simple J2EE application,the customer visits a web page (JSP). The request is sent to the web server then passed to the JSP and Servlet engine. The JSP code is executed including a search on the database. The database results are returned to the JSP page. The JSP page dynamically generates a HTML page with the data and sends it to the Customer
Advantages. • Simple of understand and initially develop. Disadvantages. • The JSP page is very difficult to maintain. It contains HTML and Java code with queries to the database. The business logic should not be in the JSP; otherwise many pages will need to be changed every time business requirements change. • Need to have data connectivity code in every JSP page. • Does not scale up very well. • Security issues - If a hacker gained access to the web server,all the confidential business logic can be read by opening the JSP files.
04/28/09 03:49:21 Web Application using EJB The following diagram shows the architecture of a typical J2EE application. This is similar to the previous example,except all business logic is contained in different EJB components.
The diagram below shows how the JSP connects to the EJB object,which queries the database. This was the JSP does not contain the database queries and some business logic has been moved into the EJB layer. The EJB container is designed to create copies (instances) of the EJB class as required in memory. This enables it to scale up as multiple requests come in.
04/28/09 03:49:21 • More secure because all the business logic is stored in the EJB components. An EJB component can be configured so only a specific user in a group can be given access to a limited set of methods. • By adding more EJB Application Servers,the system can easily scale up. However,you need to make sure the EJB components have been designed and deployed correctly. • Transaction Management support - Transaction attributes are specified on an application component during assembly. This lets you group methods into transactions across application components,which means you can easily change application components within a J2EE application and reassign the transaction attributes without changing code and recompiling. Disadvantages. • All the JSP pages need to include code that locates the EJB components. • There is still quite a bit of functionality in the JSP files. • The current architecture does not support reuse at the JSP level so all the code will need to be replicated. This will cause major maintenance problems. • The JSP pages are still too complex for web designers to use.
04/28/09 03:49:21 Web Application using reusable components Web Application using reusable components This scenario extends the previous web application. Here common and useful code is taken out of the JSP pages and moved into a JavaBean. Each JavaBean contains related methods specific to an application requirement. For example,all email methods such as mailing a message and mailing a file are stored in one JavaBean.
Advantages. • Simplifies the JSP page so a web designer can edit the design using their chosen tool. • Benefits of component reuse such as sharing common code,maintaining one set of code in one place and making testing quicker. • Allows the clean separation of tasks. One person working on making the web pages,whilst another works on the Java code.
Disadvantages. • Need to make sure the components are designed correctly (granularity) otherwise they will not be reused. • Not the most suitable for small to medium deployments as the EJB application server can consume alot of CPU and Memory resources.
04/28/09 03:49:21 Layered Approach
The actual architecture of the application has been separated out into several layers. 1. Presentation view 2. Presentation logic 3. Business logic 4. Data Model
1. Presentation view. This is the actual look,feel and presentation of the application. In J2EE,Java Server Pages (JSP) are used to implement your view. 2. Presentation Logic This is the code required to call business logic and return output to the view. Java Servlets / java beans are the best way to implement presentation logic. 3. Business Logic This is code required to execute the usecase actions and manipulate the data model. EJB Session beans are the containers of the business logic for all your usecases. 4. Data Model J2EE provides a useful abstraction for your data model,called EJB Entity beans. These are persistent objects that model your real world business abstractions.
The layered approach has the following benefits: • Encapsulation – each layer hides details from the other layers. Therefore a layer can change without affecting other layers. • Separation - Complexity in the system is easier to manage because each layer is focused on a cohesive set of responsibilities. • Reuse – each layer can provide services to the layer above,so classes can be reused whilst still abstracting the implementation details. This leads to applications that are more flexible and maintainable.
04/28/09 03:49:21 Appendix A - Summary of Recommendations
Date entered : 1st Oct 2006 Rating :No Rating Submitted by : visualbuilder
Copyright Visualbuilder.com 1999-2006 Document created date: 28 Apr 2009
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.