- the Journal of Information, Knowledge and Research in

advertisement
JOURNAL OF INFORMATION, KNOWLEDGE AND RESEARCH IN
COMPUTER ENGINEERING
MVC ARCHITECTURE : A COMPARATIVE STUDY
WITH OF IMPLEMENTATION BETWEEN
J2EE AND ASP DOT NET
1
Prof. Kalpesh A. Popat, 2 Mr. Arpit K. Ganatra
1 Asst.Professor, Faculty of Computer Applications, Marwadi Education Foundation’s
Group of Institutions, Rajkot, Gujarat.
2 B.E.[Computer Engineering] Student, Faculty of Engineering, Marwadi Education
Foundation’s Group of Institutions, Rajkot, Gujarat.
kapopat@gmail.com, arpitganatra@ymail.com
ABSTRACT: Model View Controller (MVC) is a standard design pattern used in website design or in web
application development. It is valuable due to its various capabilities like extensibility, maintainability, and
reusability. Commonly we separate a web-based application into three tier architecture. Other than web domain
MVC Architecture also uses in embedded domain. MVC achieves this by separating the application into three
logical components: Model: The model layer is responsible for the business logic of an application. It will
encapsulate access to data stores and will provide a reusable class library. Typically, within the model, you will
find facilities for database abstraction, e-mail delivery, validation, and authentication. View: The view layer is
typically considered as web design, or templating. It controls the look and feel of data and provides facilities to
collect data from the user. Technologies exclusively found in the view are HTML, CSS, and JavaScript.
Controller: The controller layer combines everything together and merges the styling of the view with the
functionality of the model. It is responsible for collecting input data from the view and deciding program
execution. The controller will call model facilities and interpret the returning data so that it can be rendered by
the view. It is also responsible for all application exception and flow control.
Keywords—MVC Architecture, Model View Controller Architecture, MVC
different user settings. There would also be a “delete”
link to remove a user, and a “create” button as well.
I: INTRODUCTION
The concept of Model-View-Controller (or MVC) is
The group page would work the same way. One way
a common one and has become increasingly popular
to implement an application like this would be for
as a design framework. However we found that most
each page to have a corresponding file written in say,
introductions to the subject are very bland and
PHP. The page for listing users would connect to the
abstract. In this paper we try to discuss some of the
database, get back all the users, and place the user
more practical reasons to go with MVC. Also while
information inside HTML that it would send back to
MVC can be used for many different kinds of
the browser. Form submissions would be handled by
application design, we will focus mostly on its use in
getting the new settings from the form, and updating
web applications. In its most basic sense, MVC is
the database.
just a clean way of organizing your code. In most
web applications, you have a database containing
While the above system works, it has a number of
multiple “business objects”, for example different
disadvantages. For one, each file would need to
products in an online store. Users can go to different
directly execute SQL statements in the database. In
pages in the application to view, update, or delete
the case of a change in schema, each file might
these “objects”, which are really just rows in a table
potentially have to be updated. Also, because the
most of the time. For any given query, the code in
HTML code is intermixed with the rest of the
your application needs to be able to access the
business logic, changes to the interface could become
database, retrieve/update the relevant objects, and
complicated. In addition there would likely be a lot of
generate HTML code to be sent back to the browser.
code that would be duplicated when it comes to
As an example, imagine a simple user management
retrieving and manipulating objects. Lets look at how
system. People can login and view a list of users.
we could code this application with MVC. We can
Each user has a name, email address, and password.
separate and consolidate all of the database code (the
In addition, there are can be user groups, which are
model), and all of the interface code (the view). All
sets of users under a given name. A simple web
of the actual database interaction lies in the model,
interface for this system would be to have two listing
which produces a number of simple methods for
pages, one of users and one for user groups. The user
manipulating objects. For any given page, there is
listing page would display a list of all users, and for
controller, which gathers the appropriate objects and
each user there would be an “edit” link, that would
passes them off to views. The view is responsible for
bring you to a new page containing a form for the
displaying the data in a user interface, is often 90%
ISSN: 0975 – 6760| NOV 12 TO OCT 13 | VOLUME – 02, ISSUE – 02
Page 213
JOURNAL OF INFORMATION, KNOWLEDGE AND RESEARCH IN
COMPUTER ENGINEERING
HTML/JavaScript, with the rest being embedded
code (like PHP or Perl) or a template language (like
JSTL). There are many benefits to such a system.
First, development can be simplified by allowing the
designers to work on HTML and CSS code, and
programmers to work on the backend model. These
two pieces can be combined with small, simple
controllers. Another benefit is in testing. The core of
the application lies in the model, which can be tested
programmatically dealing with any interface.
Changing and updating the user interface is also
much easier. In case we described above, MVC is
used as way of organizing code. However, there are a
number of frameworks that use MVC to make
developing an application simpler. This includes
spring for Java (which is now used by RSP Web as of
version 2.1), Maypole for Perl, php.MVC for PHP,
Rails for Ruby, and many more. These frameworks
can make development even simpler, by including
interfaces for base model objects, views (often with
template languages), and controller classes.
II: MVC FOR THE WEB
To apply MVC to the Web, we use a combination of
scripts, server pages, and ordinary objects to
implement the various components in a framework
we call Web Actions. In this context, both versions of
the MVC are relevant, particularly the dual uses of
the term controller. For HTTP applications, input and
presentation are entirely separate, so an input
controller distinct from the view is useful. For
applications of any complexity, we also need an
application controller to separate the details of
application flow from the business logic. Figure 3
shows the framework’s basic object structure.
III: ASP.NET MVC FRAMEWORK
ASP.Net started off using a pattern called
Model-View-Presenter, but this pattern got
"replaced" when Microsoft introduced ASP.Net
MVC, which implements a similar MVC pattern used
in Rails or Django. CodeGuru has a good blog post
on MVP vs. MVC and in it there's a good graphic
explaining the difference between these two patterns:
Figure 4 ASP.Net MVC framework
IV: Implementing MVC with J2EE
From the time that web was used for something than
showing static information, developers had to solve a
lot of problems derived from HTTP and HTML
because they were not thought to support, so many
things necessaries to give dynamism to web. So, new
concepts and tools were developed to make
ISSN: 0975 – 6760| NOV 12 TO OCT 13 | VOLUME – 02, ISSUE – 02
Page 214
JOURNAL OF INFORMATION, KNOWLEDGE AND RESEARCH IN
COMPUTER ENGINEERING
programming web applications easier and possible
such sessions, cookies, etc. We will try to take
advantage of these and many other technologies
when considered appropriate to help the MVC
implementation. In this point it is explained how to
implement our MVC model and what technologies
we are using for it. In Figure 5 we show a scheme of
this and in Figure 6 a web application request
collaboration diagram.
Figure 7 : Comparison of MVC implementation
Figure 5 : Scheme of the design. It shows the
collaboration between different layers
VI: Overall Comparison Without Framework
So as we all know in MVC the first hit comes to the
controller and the controller binds the view with the
model and sends it to the end user. Model, view and
controller form the three core pillars for MVC.
Table 1 : Overall Comparison without Framework
Below is simple pictorial representation of how
things actually look like.
Figure 6 : Web application request collaboration
diagram
V: Comparison of MVC implementation between
J2EE and ASP.NET
How one technology is better than other in
implementing MVC. The fact is both the
technologies have their own way of doing things. To
do full justice in terms of comparison is divided in
two parts. In the first part we will compare MVC
implementation without using framework and tools.
In the second part we will bring up the comparison of
MVC using j2EE struts as compared to ASP.NET
MVC visual studio template.
Figure 8 : Pictorial View
VII: The Sample for Comparison
In order to do a proper comparison we have taken a
common example. In this example we will do the
following:
 When the user comes to the web site, the
first page user will see is the Index page. So
if it is ASP.NET user will see index.aspx
page, if it is J2EE user will see index.jsp
page.
 Index page is nothing but a simple page
which takes username and password and
sends a login command to the controller.
ISSN: 0975 – 6760| NOV 12 TO OCT 13 | VOLUME – 02, ISSUE – 02
Page 215
JOURNAL OF INFORMATION, KNOWLEDGE AND RESEARCH IN
COMPUTER ENGINEERING


Once the controller gets the login command,
user creates the object of the model and
checks if the user is proper or not.
If the user is proper then controller sends the
user to welcome view page or else user will
be redirected to the error view page.
In the controller we can get the data from request and
response using in both technologies using the below
code.
We then call the “isValid” function of the model and
redirect to welcome page or to the home page
depending on if he is a valid user or not. To redirect
in J2EE we use the “RequestDispatcher” class and to
redirect in ASP.Net we use the “response.redirect”
function.
Figure 9 : A Sample for Comparison
VIII : The Model – Java Bean in J2EE and .NET
class in ASP.NET
Let’s start with the simplest part of MVC i.e. model.
For the above example we will create a simple class
called as “User”, this class will have two properties
“Username” and “Password”. The client, which for
now the controller will set these two properties, can
call the “IValid” function to check if the user is valid
or not. In J2EE the model is nothing but the Java
bean class, in .NET it’s a simple class with setter and
getters.
IX : The Controller – Servlet in J2EE and
HttpHandler in ASP.NET
The next important part is the controller. The
controller forms the heart of MVC. To create a
controller in J2EE we create a class which inherits
from “HttpServlet” class. The logic of the controller
is written in the “processrequest” method. You can
access the request and response object using the
“HttpServletRequest” and “HttpServletResponse”
classes. To create a controller in ASP.NET we
implement the “IHttpHandler” class and override the
“processrequest” with the controller logic. Below is
the simple code of how the controllers are
implemented in both the technologies. To Access the
request and response object we need to use the
context class in ASP.NET while in J2EE its available
as the part of function with different objects as shown
in the below code snippet.
X : The mapping XML files – Web.xml in J2EE
and Web.config in ASP.NET
Now that we have created the controller, we need to
map the actions or the URL pattern with the
controller. In other word when someone sends an
action or URL pattern as “Login” we need to ensure
that it invokes the appropriate controller. Mapping of
pattern/action to the controller in both technologies is
done by using a configuration XML file. In J2EE this
configuration file is called as the “Web.xml” file and
in ASP.NET it‟s called as “Web.config”. In J2EE in
web.xml we first need to map which URL pattern
maps with which servlet. For instance you can see in
the below web.xml code snippet we have mapped the
Login pattern with LoginServlet servlet name.
XI : The View – Servlet in J2EE and HttpHandler
in ASP.NET
The next important part is the view. The view is
nothing but a simple page with the form tag and
action having the URL pattern. You can see how the
index.jsp and the index.aspx have the action to Login
URL pattern. This URL pattern is then mapped in the
web.xml and web.config file to the appropriate
controller.
ISSN: 0975 – 6760| NOV 12 TO OCT 13 | VOLUME – 02, ISSUE – 02
Page 216
JOURNAL OF INFORMATION, KNOWLEDGE AND RESEARCH IN
COMPUTER ENGINEERING
7.
Venkat, N. T. (n.d.). Advantages &
Disadvantages of MVC Architecture. Retrieved
November
3,
2012,
from
http://www.allinterview.com/:
http://www.allinterview.com/showanswers/56984.ht
ml
XII : Conclusion and Future Directions
Model-View-Controller has lasted over 30 years and
is used in most modern GUI-frameworks and
web-frameworks. It has proven its worth and it's here
to stay. We would expect it being used more and
more, especially for next-generation frameworks.
MVC does produce more code than hack-and-slash
HTML code and it's not that suitable if you code
small web-applications. But it should be very suitable
if you want to code large web-applications where
maintainability, reusability and testability are
important. In the future, incorporating this
architecture into an Integrated Development
Environment will enable faster developing giving to
the programmer the possibility of generating big parts
of his code automatically. Moreover, building the
user interface hierarchically, so it can be used the
same delegation as in object oriented technology,
makes that repercussions in changing code of the
application are very limited.
REFRENCES
1.
Alan Knight, N. D. (2002). Objects and the
Web. IEEE SOFTWARE , 51-59.
2.
Amir Salihefendic. (2011, March). Model
View Controller: History, Theory and Usage.
Retrieved
November
2,
2012,
from
http://www.amix.dk: http://amix.dk/blog/post/19615
3.
Kingsley Sage. (n.d.). Model
Controller (MVC) architecture. 18-27.
View
4.
Marty Hall, L. B. (2003). Integrating
Servlets and JSP: The Model View Controller (MVC)
Architecture. In L. B. Marty Hall, Core Servlets and
JavaServer Pages: Volume 1: Core Technologies (pp.
434-463). Prentice Hall PTR.
5.
Micael Gallego-Carrillo, I. G.-A.-H. (2005).
Applying Hierarchical MVC Architecture To High
Interactive Web Application . Third International
Conference I.TECH - 2005, (pp. 1-6).
6.
Shivprasad Koirala. (2011, March 17).
Comparison of MVC implementation between J2EE
and ASP.NET, Who is the best? Part 1. Retrieved
November
3,
2012,
from
http://www.dotnetfunda.com/:
http://www.dotnetfunda.com/articles/article1254comparison-of-mvc-implementation-between-j2eeand-aspnet-who-is-the-best.aspx
ISSN: 0975 – 6760| NOV 12 TO OCT 13 | VOLUME – 02, ISSUE – 02
Page 217
Download