• No results found

MVC pattern in java web programming

N/A
N/A
Protected

Academic year: 2021

Share "MVC pattern in java web programming"

Copied!
112
0
0

Loading.... (view fulltext now)

Full text

(1)

MVC pattern in java web programming

Aleksandar Kartelj, Faculty of Mathematics Belgrade

DAAD workshop Ivanjica 6. -11.9.2010 Serbia

(2)

Outline

1 Introduction 2 Page controller 3 Front controller 4 Java Struts 1.x 5 ASP.NET 6 Conclusions

(3)

History

Simple information portals in early nineties

Two major standard for building web apps: ASP.NET and Apache Struts (along with J2EE framework)

Standard patterns implemented in ASP.NET and Struts have helped reduce code complexity and accelerate development times

(4)

History

Simple information portals in early nineties

Two major standard for building web apps: ASP.NET and Apache Struts (along with J2EE framework)

Standard patterns implemented in ASP.NET and Struts have helped reduce code complexity and accelerate development times

(5)

History

Simple information portals in early nineties

Two major standard for building web apps: ASP.NET and Apache Struts (along with J2EE framework)

Standard patterns implemented in ASP.NET and Struts have helped reduce code complexity and accelerate development times

(6)

History

In the early days of the Web, most business Web sites were simply a form of advertisement

The dot-com revolution showed businesses that they could also provide online services for their customers.

Early e-commerce Web sites were often powered by Java-based technologies, including JSPs, EJBs, Servlets, and JDBC; or Microsoft-based technologies, including ASP, VBScript, MTS, ADO, COM and COM+.

(7)

History

In the early days of the Web, most business Web sites were simply a form of advertisement

The dot-com revolution showed businesses that they could also provide online services for their customers.

Early e-commerce Web sites were often powered by Java-based technologies, including JSPs, EJBs, Servlets, and JDBC; or Microsoft-based technologies, including ASP, VBScript, MTS, ADO, COM and COM+.

(8)

History

In the early days of the Web, most business Web sites were simply a form of advertisement

The dot-com revolution showed businesses that they could also provide online services for their customers.

Early e-commerce Web sites were often powered by Java-based technologies, including JSPs, EJBs, Servlets, and JDBC; or Microsoft-based technologies, including ASP, VBScript, MTS, ADO, COM and COM+.

(9)

J2EE standard

In the spring of 1999, Sun released the J2EE standard

Although the front end was well architected and scalable, the system still broke down because the back-end business logic The need for more integrated business tools and Web services became apparent.

This background laid the framework for the pattern revolution in J2EE.

(10)

J2EE standard

In the spring of 1999, Sun released the J2EE standard Although the front end was well architected and scalable, the system still broke down because the back-end business logic

The need for more integrated business tools and Web services became apparent.

This background laid the framework for the pattern revolution in J2EE.

(11)

J2EE standard

In the spring of 1999, Sun released the J2EE standard Although the front end was well architected and scalable, the system still broke down because the back-end business logic The need for more integrated business tools and Web services became apparent.

This background laid the framework for the pattern revolution in J2EE.

(12)

J2EE standard

In the spring of 1999, Sun released the J2EE standard Although the front end was well architected and scalable, the system still broke down because the back-end business logic The need for more integrated business tools and Web services became apparent.

This background laid the framework for the pattern revolution in J2EE.

(13)

Model view controller

Denition

Model View Controller (MVC) is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates domain logic(the application logic for the user) from input and presentation (UI), permitting independent

(14)
(15)

Model

Denition

The model is used to manage information and notify observers when that information changes. The model is the domain-specic representation of the data upon which the application operates. Domain logic adds meaning to raw data (for example, calculating whether today is the user's birthday, or the totals, taxes, and shipping charges for shopping cart items). When a model changes its state, it noties its associated views so they can be refreshed.

(16)

View

Denition

The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for dierent purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.

(17)

Controller

Denition

The controller receives input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and viewport to perform actions based on that input.

(18)
(19)
(20)

Case example - Web Server

The Model is the module which interacts with the database using for example SQL

The View is the module which generates HTML from the data The Controller contains all the other functionality of the server (eg. it decides which page to display, generates dynamic content, handles session and cookie data, etc.)

(21)

Case example - Web Server

The Model is the module which interacts with the database using for example SQL

The View is the module which generates HTML from the data

The Controller contains all the other functionality of the server (eg. it decides which page to display, generates dynamic content, handles session and cookie data, etc.)

(22)

Case example - Web Server

The Model is the module which interacts with the database using for example SQL

The View is the module which generates HTML from the data The Controller contains all the other functionality of the server (eg. it decides which page to display, generates dynamic content, handles session and cookie data, etc.)

(23)

Motivation

Controller - View separation. Controller is completely unaware of the actual output format being used. Various views: html, pdf, ash...

Controller - Model separation. Data is stored can be easily changed without having to modify the Controller or the View. Dierent data storage: raw le, database, xml..

(24)

Motivation

Controller - View separation. Controller is completely unaware of the actual output format being used. Various views: html, pdf, ash...

Controller - Model separation. Data is stored can be easily changed without having to modify the Controller or the View. Dierent data storage: raw le, database, xml..

(25)

Outline

1 Introduction 2 Page controller 3 Front controller 4 Java Struts 1.x 5 ASP.NET 6 Conclusions

(26)

MVC in ASP.NET

ASP.NET implements MVC using the Page Controller pattern.

The Page Controller pattern applies the controller at the level of individual pages.

The ASP.NET runtime intercepts page requests, invokes the requested actions on the model, and determines the correct view to use for the resulting page.

The interception and dispatching logic is automated and hidden from developers

ASP.NET divides each page into two parts: a View that contains the various controls, and the code-behind

(27)

MVC in ASP.NET

ASP.NET implements MVC using the Page Controller pattern. The Page Controller pattern applies the controller at the level of individual pages.

The ASP.NET runtime intercepts page requests, invokes the requested actions on the model, and determines the correct view to use for the resulting page.

The interception and dispatching logic is automated and hidden from developers

ASP.NET divides each page into two parts: a View that contains the various controls, and the code-behind

(28)

MVC in ASP.NET

ASP.NET implements MVC using the Page Controller pattern. The Page Controller pattern applies the controller at the level of individual pages.

The ASP.NET runtime intercepts page requests, invokes the requested actions on the model, and determines the correct view to use for the resulting page.

The interception and dispatching logic is automated and hidden from developers

ASP.NET divides each page into two parts: a View that contains the various controls, and the code-behind

(29)

MVC in ASP.NET

ASP.NET implements MVC using the Page Controller pattern. The Page Controller pattern applies the controller at the level of individual pages.

The ASP.NET runtime intercepts page requests, invokes the requested actions on the model, and determines the correct view to use for the resulting page.

The interception and dispatching logic is automated and hidden from developers

ASP.NET divides each page into two parts: a View that contains the various controls, and the code-behind

(30)

MVC in ASP.NET

ASP.NET implements MVC using the Page Controller pattern. The Page Controller pattern applies the controller at the level of individual pages.

The ASP.NET runtime intercepts page requests, invokes the requested actions on the model, and determines the correct view to use for the resulting page.

The interception and dispatching logic is automated and hidden from developers

ASP.NET divides each page into two parts: a View that contains the various controls, and the code-behind

(31)
(32)
(33)
(34)

Benets using page controller pattern

1 Simplicity

2 Built-in framework features 3 Increased reuse

4 Expandability

(35)

Benets using page controller pattern

1 Simplicity

2 Built-in framework features 3 Increased reuse

4 Expandability

(36)

Benets using page controller pattern

1 Simplicity

2 Built-in framework features 3 Increased reuse

4 Expandability

(37)

Benets using page controller pattern

1 Simplicity

2 Built-in framework features 3 Increased reuse

4 Expandability

(38)

Benets using page controller pattern

1 Simplicity

2 Built-in framework features 3 Increased reuse

4 Expandability

(39)

Liabilities of using page controller pattern

1 One controller per page 2 Deep inheritance trees

(40)

Liabilities of using page controller pattern

1 One controller per page 2 Deep inheritance trees

(41)

Liabilities of using page controller pattern

1 One controller per page 2 Deep inheritance trees

(42)

Outline

1 Introduction 2 Page controller 3 Front controller 4 Java Struts 1.x 5 ASP.NET 6 Conclusions

(43)

MVC in Struts

The Struts architecture is essentially derived from a combination of the Front Controller and Intercepting Filter patterns

Single controller that governs the application events

Filters, for example, the Struts Validator is a lter that ensures that the controller receives only validated requests

The controller itself is usually implemented in two parts: a handler and a hierarchy of commands (Gamma, 1995)

(44)

MVC in Struts

The Struts architecture is essentially derived from a combination of the Front Controller and Intercepting Filter patterns

Single controller that governs the application events

Filters, for example, the Struts Validator is a lter that ensures that the controller receives only validated requests

The controller itself is usually implemented in two parts: a handler and a hierarchy of commands (Gamma, 1995)

(45)

MVC in Struts

The Struts architecture is essentially derived from a combination of the Front Controller and Intercepting Filter patterns

Single controller that governs the application events

Filters, for example, the Struts Validator is a lter that ensures that the controller receives only validated requests

The controller itself is usually implemented in two parts: a handler and a hierarchy of commands (Gamma, 1995)

(46)

MVC in Struts

The Struts architecture is essentially derived from a combination of the Front Controller and Intercepting Filter patterns

Single controller that governs the application events

Filters, for example, the Struts Validator is a lter that ensures that the controller receives only validated requests

The controller itself is usually implemented in two parts: a handler and a hierarchy of commands (Gamma, 1995)

(47)
(48)
(49)
(50)

Benets using front controller pattern

1 Centralized control 2 Thread-safety 3 Congurability

(51)

Benets using front controller pattern

1 Centralized control 2 Thread-safety 3 Congurability

(52)

Benets using front controller pattern

1 Centralized control

2 Thread-safety

(53)

Liabilities of using front controller pattern

1 Performance considerations 2 Increased complexity

(54)

Liabilities of using front controller pattern

1 Performance considerations

(55)

Outline

1 Introduction 2 Page controller 3 Front controller 4 Java Struts 1.x 5 ASP.NET 6 Conclusions

(56)

Overview

1 Follows MVC architecture

2 Utilizes a centralized servlet controller 3 Multiple business logic adapters, JSP page 4 structs-cong.xml conguration le

(57)

Overview

1 Follows MVC architecture

2 Utilizes a centralized servlet controller 3 Multiple business logic adapters, JSP page 4 structs-cong.xml conguration le

(58)

Overview

1 Follows MVC architecture

2 Utilizes a centralized servlet controller 3 Multiple business logic adapters, JSP page 4 structs-cong.xml conguration le

(59)

Overview

1 Follows MVC architecture

2 Utilizes a centralized servlet controller 3 Multiple business logic adapters, JSP page 4 structs-cong.xml conguration le

(60)

Overview

1 Follows MVC architecture

2 Utilizes a centralized servlet controller 3 Multiple business logic adapters, JSP page 4 structs-cong.xml conguration le

(61)

M - V - C

The model contains the business logic and interact with the persistance storage to store, retrive and manipulate data. Mainly implemented with JavaBeans or EJB components

The view is responsible for dispalying the results back to the user. Tech: JSP, Struts tags library, Tile framework, XLST etc. ActionServlet, Action classes (Command design pattern implementation of the Java Servlet technology).

(62)

M - V - C

The model contains the business logic and interact with the persistance storage to store, retrive and manipulate data. Mainly implemented with JavaBeans or EJB components The view is responsible for dispalying the results back to the user. Tech: JSP, Struts tags library, Tile framework, XLST etc.

ActionServlet, Action classes (Command design pattern implementation of the Java Servlet technology).

(63)

M - V - C

The model contains the business logic and interact with the persistance storage to store, retrive and manipulate data. Mainly implemented with JavaBeans or EJB components The view is responsible for dispalying the results back to the user. Tech: JSP, Struts tags library, Tile framework, XLST etc. ActionServlet, Action classes (Command design pattern implementation of the Java Servlet technology).

(64)
(65)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which

extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class

returns an ActionForward to the controller.

6 The action class process the request with the help of the

model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the

appropriate view.

8 The HTTP response is rendered back to the user by the view

(66)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class

returns an ActionForward to the controller.

6 The action class process the request with the help of the

model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the

appropriate view.

8 The HTTP response is rendered back to the user by the view

(67)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class

returns an ActionForward to the controller.

6 The action class process the request with the help of the

model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the

appropriate view.

8 The HTTP response is rendered back to the user by the view

(68)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class

returns an ActionForward to the controller.

6 The action class process the request with the help of the

model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the

appropriate view.

8 The HTTP response is rendered back to the user by the view

(69)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class returns an ActionForward to the controller.

6 The action class process the request with the help of the

model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the

appropriate view.

8 The HTTP response is rendered back to the user by the view

(70)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class returns an ActionForward to the controller.

6 The action class process the request with the help of the model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the

appropriate view.

8 The HTTP response is rendered back to the user by the view

(71)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class returns an ActionForward to the controller.

6 The action class process the request with the help of the model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the appropriate view.

8 The HTTP response is rendered back to the user by the view

(72)

Workow

1 The ActionServlet receives the request.

2 Bundles all the request values into a JavaBean class which extends Struts ActionForm class.

3 Decides which action class to invoke to process the request. 4 Validate the data entered by the user.

5 After completing the request processing the Action class returns an ActionForward to the controller.

6 The action class process the request with the help of the model component. The model interacts with the database and process the request.

7 Based on the ActionForward the controller will invoke the appropriate view.

8 The HTTP response is rendered back to the user by the view

(73)

struts-cong.xml

Contains the details regarding the Actions, ActionForms, ActionMappings and ActionForwards.

During the startup the ActionServelet reads the

struts-cong.xml le and creates a database of conguration objects.

Later while processing the request the ActionServlet makes decision by refering to this object.

(74)
(75)
(76)
(77)
(78)
(79)
(80)
(81)
(82)
(83)
(84)
(85)
(86)
(87)

Outline

1 Introduction 2 Page controller 3 Front controller 4 Java Struts 1.x 5 ASP.NET 6 Conclusions

(88)
(89)
(90)
(91)
(92)
(93)

Outline

1 Introduction 2 Page controller 3 Front controller 4 Java Struts 1.x 5 ASP.NET 6 Conclusions

(94)
(95)
(96)

J2EE vs ASP.NET

As Web applications mature, the need for a robust, fully-integrated development system increases

Each framework oers a wide range of features and benets for application development.

On a development level, developing with ASP.NET involves less code than Struts

Many features, such as validation, caching and tracing, are built into ASP.NET, whereas Struts requires third-party components

(97)

J2EE vs ASP.NET

As Web applications mature, the need for a robust, fully-integrated development system increases

Each framework oers a wide range of features and benets for application development.

On a development level, developing with ASP.NET involves less code than Struts

Many features, such as validation, caching and tracing, are built into ASP.NET, whereas Struts requires third-party components

(98)

J2EE vs ASP.NET

As Web applications mature, the need for a robust, fully-integrated development system increases

Each framework oers a wide range of features and benets for application development.

On a development level, developing with ASP.NET involves less code than Struts

Many features, such as validation, caching and tracing, are built into ASP.NET, whereas Struts requires third-party components

(99)

J2EE vs ASP.NET

As Web applications mature, the need for a robust, fully-integrated development system increases

Each framework oers a wide range of features and benets for application development.

On a development level, developing with ASP.NET involves less code than Struts

Many features, such as validation, caching and tracing, are built into ASP.NET, whereas Struts requires third-party components

(100)

J2EE vs ASP.NET

What are the real advantages of using J2EE over ASP.net?

Microsoft sometimes make random changes to their

technology direction, and you have no recourse because you are locked into a single-vendor solution

Is there anything that cannot be done in ASP.net that can be done in J2EE?

In J2EE, standards compliance means you can re any vendor and replace them with a better, more responsive vendor. Also, once the frameworks are all in place and congured, is it faster to develop apps in J2EE than it is in .net? No.

(101)

J2EE vs ASP.NET

What are the real advantages of using J2EE over ASP.net?

Microsoft sometimes make random changes to their

technology direction, and you have no recourse because you are locked into a single-vendor solution

Is there anything that cannot be done in ASP.net that can be done in J2EE?

In J2EE, standards compliance means you can re any vendor and replace them with a better, more responsive vendor. Also, once the frameworks are all in place and congured, is it faster to develop apps in J2EE than it is in .net? No.

(102)

J2EE vs ASP.NET

What are the real advantages of using J2EE over ASP.net? Microsoft sometimes make random changes to their

technology direction, and you have no recourse because you are locked into a single-vendor solution

Is there anything that cannot be done in ASP.net that can be done in J2EE?

In J2EE, standards compliance means you can re any vendor and replace them with a better, more responsive vendor. Also, once the frameworks are all in place and congured, is it faster to develop apps in J2EE than it is in .net? No.

(103)

J2EE vs ASP.NET

What are the real advantages of using J2EE over ASP.net? Microsoft sometimes make random changes to their

technology direction, and you have no recourse because you are locked into a single-vendor solution

Is there anything that cannot be done in ASP.net that can be done in J2EE?

In J2EE, standards compliance means you can re any vendor and replace them with a better, more responsive vendor. Also, once the frameworks are all in place and congured, is it faster to develop apps in J2EE than it is in .net? No.

(104)

Motivation

Web programming is part of a Software Engineering course on Faculty of Mathematics in Belgrade

In the past few years page controller concept through asp.net was preferable

In general .NET technologies were used in this course

Students don't learn java based web programming through this or any other course

(105)

Motivation

Web programming is part of a Software Engineering course on Faculty of Mathematics in Belgrade

In the past few years page controller concept through asp.net was preferable

In general .NET technologies were used in this course

Students don't learn java based web programming through this or any other course

(106)

Motivation

Web programming is part of a Software Engineering course on Faculty of Mathematics in Belgrade

In the past few years page controller concept through asp.net was preferable

In general .NET technologies were used in this course

Students don't learn java based web programming through this or any other course

(107)

Motivation

Web programming is part of a Software Engineering course on Faculty of Mathematics in Belgrade

In the past few years page controller concept through asp.net was preferable

In general .NET technologies were used in this course

Students don't learn java based web programming through this or any other course

(108)

Final conclusion

Technology shouldn't be discussed. It is much like a matter of taste

Here, the web programming concept is questioned. Too bad is that java vendors focused on front controller, and Microsoft on page controller pattern

In the past few years MS made its own MVC framework Both concept should be a part of course, so question arise: Java based MVC framework or still developing asp.net MVC framework?

(109)

Final conclusion

Technology shouldn't be discussed. It is much like a matter of taste

Here, the web programming concept is questioned. Too bad is that java vendors focused on front controller, and Microsoft on page controller pattern

In the past few years MS made its own MVC framework Both concept should be a part of course, so question arise: Java based MVC framework or still developing asp.net MVC framework?

(110)

Final conclusion

Technology shouldn't be discussed. It is much like a matter of taste

Here, the web programming concept is questioned. Too bad is that java vendors focused on front controller, and Microsoft on page controller pattern

In the past few years MS made its own MVC framework

Both concept should be a part of course, so question arise: Java based MVC framework or still developing asp.net MVC framework?

(111)

Final conclusion

Technology shouldn't be discussed. It is much like a matter of taste

Here, the web programming concept is questioned. Too bad is that java vendors focused on front controller, and Microsoft on page controller pattern

In the past few years MS made its own MVC framework

Both concept should be a part of course, so question arise: Java based MVC framework or still developing asp.net MVC framework?

(112)

References

Related documents

I argue that positive global coverage of Jamaica’s outstanding brand achievements in sports, music and as a premier tourism destination, is being negated by its rival brands –

innovation in payment systems, in particular the infrastructure used to operate payment systems, in the interests of service-users 3.. to ensure that payment systems

National Conference on Technical Vocational Education, Training and Skills Development: A Roadmap for Empowerment (Dec. 2008): Ministry of Human Resource Development, Department

When transfecting HEK 293T cells with either “mIFP-P2A-mNG2(full)” or “mIFP- P2A-mNG211SpyCatcher and mNGX1-10 (X represent 2, 3A or 3K)”, we observed both mNG31-10

The encryption operation for PBES2 consists of the following steps, which encrypt a message M under a password P to produce a ciphertext C, applying a

Increased competition and the current economic crisis have brought about an unfavorable business climate for dental practices, but also have had a positive effect on the wider

This paper articulates how the first phase of a design research approach was applied to explore possible solutions for designing and implementing effective online higher

We have found that the socioeconomic composition of the higher education student body changed somewhat between 1988 and 1993 in Australia, with the main change being the