Front Controller – Struts Tutorial

Front Controller:-

A special web resource program in the web application i.e capable of trapping & taking request coming to other web resource programs of web application is called as front controller.

Front controller contains the common & global prerequest process logic like authentication & authorization logics.

Servlet or JSP program becomes front controller only when it contains extension or directory match URL patterns.

  • Front controller is not responsible to trap the response generated by other web resource programs. But it is responsible to trap request going to other web resource programs.
  • The servlet filter program is capable of trapping both request & response of other web resource programs.
  • In struts application Action Servlet in configured as front controller servlet for this extension match, directory matches URL pattern should be specified for Action Servlet in web.xml file.
  • Even through Action Servlet is built in servlet its configuration in web.xml file having extension match or directory match URL pattern is the responsibility of program.

Question:- Why Action Servlet should be configured as front controller?

  1. Struts Action class is an ordinary java class so it cannot take http request directly from the clients even though it contains business logic to process the request. To overcome these problems we make Action Servlet as mediator to take http request from browser window and to pass that request to an appropriate action class. To make this Action Servlet trapping & taking the entire request coming to all the Action classes of Struts application it must be configured as “front controller”.
  • Programmers generally configure Action Servlet in web.xml file as shown below.

In web.xml:-

     <web-app>

         <servlet>

            <servlet-name>action</servlet-name>

            <servlet-class>org.apache.struts.action.Actionservlet</servlet-class>

            <init-param>

               <param-name>config</param-name>

               <param-values>/web-inf/struts-config.xml</param-value>

            </init-param>

            <load – on -startup>2</load –on – startup>

        </servlet>

        <servlet-mapping>

               <s-n> action </s-n>

               <u-p>*.do</u-p>

         </servlet-mapping>

     </web-app>

  • As a front controller Action Servlet traps the request coming from the clients to Action classes (like browsers window). As a controller of struts based & MVC2 Architecture based web application it traps the request given by Action class and passes them to result jsp pages of view layer.
  • There are 2 ways pass input values to servlet program from outside the servlet program.
  1. Request parameters ( from client side )
  2. Init parameters / context parameters ( from server side )
  • Use request parameters to send non technical input values to servlet program from browser window. (as from data)
  • Use Init / context parameters to send technical input values from web.xml file by programmer. (like jdbc driver details)
  • Since the name & location of struts-configuration file is technical input value required by Action Servlet, so we use the Init parameter “config” to supply that value during Action Servlet configuration (refer above web.xml)
  • When load-on-startup is not enable on a servlet program the first request to given servlet program participate in instantiation & initialization process before processing request by executing service method where as the other first request given to servlet program directly passes the request by calling service method.

Due to this the response time of first request will be little bit high when you compare with the response time of other than first request.

To equalize with response time other than first request make sevlet container perform instantiation & initialization operation on servlet program during server startup by enabling load-on-startup on servlet. So the first request given to servlet program directly executes service method & process the request.

  • It is recommended to enable i-o-s Action Servlet to equalize response time of first request time of other than first request.
  • When multiple servlets of web app’s are enable with L-O-S in which order their object will be created either during server startup or during the deployment of web application will be decided based on their I-O-S priority values. High value gives low priority. Low values give high priority. Zero (0) gives least priority. Negative values give ignored the enabled <I-O-S>.

Note: – In Tomcat 6.0 for zero there is no separate meaning for I-O-S priority. Enable in <L-O-S> on a servlet program with –ve value is equal to not enabling L-O-S on servlet program.

Classic web application (other than Tomcat 6.0):-

                      <L-O-S>value

Srv 1                   4 (3)

Srv 2                   3 (2)

Srv 3                   0 (4)

Srv 4                   1 (1)

Classic web application (other than Tomcat 6.0)

                       <I-O-S>value

Srv 1                   14 (0)

Srv 2                    -3 <L-O-S> is ignored

Srv 3                     2 (1)

Srv 4                     0 (3)

Classic web application (other than Tomcat 6.0)

                      <I-O-S>value

Srv 1                   3

Srv 2                    3

Srv 3                    3

Srv 4                    3

  • Since Action Servlet is the only one servlet of struts based web application the programmer can use any positive number or zero as <I-O-S> priority value while configuring Action Servlet in web.xml file.

Singleton Design Pattern – Struts Tutorial

Singleton Java Class:-

  • In java class that allows creating only one object per JVM is called as “singleton java class”. Instead of creating multiple objects per a class on a single JVM having same data. It is recommended to create only one object for that class and use it for multiple times by taking support of singleton java class.
  • Every servlet program is a single instance multiple threads component. That means when multiple request are given to a servlet program the servlet container creates only one object of our servlet program and starts multiple threads on that object requesting multiple requests. 

Question: every servlet is a single instance multiple threads component. Action servlet is also servlet then what is the need of giving Action Servlet class as singleton java class?

  1. Some servers violates above said servlet specification principle by creating multiple objects for single servlet class when that servlet gets huge number of request parallel or concurrently. (300+)
  • When struts application is deployed in this kind of servers to see only one object for Action Servlet the creators of struts s/w have made Action Servlet as singleton java class even though Action Servlet gets huge number of requests simultaneously or concurrently.

Note: – Our normal servlet classes are not singleton java classes but ActionServlet is explicitly design singleton java class based Servlet program.

  • Every Servlet program of web application will be identified through its url-pattern there are three ways to provide url-pattern to a servlet program.
  1. Exact match
  2. Directory match
  3. Extension match

Exact match:-

This url-pattern must begin with “/” symbol and should not contain “*” character. Multiple words or multiple letters can be there separated with “/” symbol.

1)      <url-pattern> / abc</url pattern>

2)      <url-pattern>/ abc/xyz</url-pattern>

3)      <url-pattern>/abc.do</url-pattern>

  • Examples request urls from browser window to given request to a servlet

Program whose url pattern is /abc.

http:// localhost: 2020/Test App/abc is valid.

                                                                     /Test App/xyz/abc is invalid.

                                                                     /Test App/xyz is invalid.

                                                                     /Test App/abc.do is invalid.

Directory match:-

Example: – <url-pattern>/x/y/*</url-pattern>

  • This url-pattern must begin ’/’ symbol and must end with ‘*’ symbol.

Example: – Request urls from browser window to give request to a servlet program whose url pattern is “/x/y/*”.                  

                         http://localhost:2020/Test App/x/y/abc is valid

                                                                      /Test App/x/y/123/* is valid  

                                                                      /Test App/y/x/x/y/abc is invalid

                                                                      /Test App/x/y is valid

                                                                      /Test App/x is invalid

                                                                      /Test App/y/x is invalid

Other example directory match url-pattern:-

1)      <url-pattern> /xyz/abc/*</url-pattern>

2)      <url-pattern> /xyz/*</url-pattern>

3)      <url-pattern> /x/y/abc/*</url-pattern>

Extension match: –   this <url-pattern> must begin with “*” symbol and must end with extension word or letter.

Example: – <url-pattern> *.do</url-pattern>

                     <url-pattern>*.123</url-pattern>

Example request urls from browser window to give request to servlet program url pattern is “*.do”

             http://localhost:2020/TestApp/abc.do is valid

                                                    /TestApp/a/b/xyz.do is valid

                                                    /TestApp/x/a/abc.do is valid

                                                    /TestApp/.do is valid

                                                    /TestApp/abc.xyz is invalid

                                                    /TestApp/abc.do/xyz.c is invalid

Other examples of extension match url-patterns:

Example: –

1)      <url-pattern> *.c</url-pattern>

2)      <url-pattern> *.cpp</url-pattern>

3)      <url-pattern> *.xyz</url-pattern>

Note: – you cannot frame <u-p> to a servlet by mixing up multiple styles.

Example: – <u-p> /x/ y/*.do </u-p>

         The url-pattern formation itself invalid in web.xml file.bc3 the above url-pattern is not according to above specified styles.

Architecture of struts 1.x application – Struts Tutorial

Architecture of Struts 1.x Application

  • In the Architecture of struts 1.x application business logic is placed directly in the Action class so it comes under model layer resource.
  1. Programmer deploys Struts application web server/application server. During this process server performs some initial operation on the deployed struts application.
  2. End user launches web page or form page of Struts application on browser window.
  3. End user submits request from form page having form data.
  4. The controller servlet called ActionServlet traps & takes the request based on its configuration done in web .xml file and also reads form data from form page.
  5. ActionServlet uses Struts configure file entries to generate integration logic & to decide form bean, Struts Action class to process the request.
  6. ActionServlet  creates / locates form bean class object and writes the received form data to it.
  7. The form validation logic of form bean class validates the form data.
  8. ActionServlet creates /locates struts action class object.
  9. ActionServlet calls execute method of struts Action class.
  10. This execute method processes the request by using business logic and sends the result & control to ActionServlet.
  11. ActionServlet uses Action forward configures of struts configure File to decide the result page of Action class.
  12. ActionServlet passes the result control to result page.
  13. Presentation logic of result page formats the result the result and sends response to browser window as dynamic webpage.

Note:- form bean class object is visible in the execute method of struts Action class as parameter value.

Struts software created by using multiple technologies so to use these technologies effectively the creators of struts software have implemented some design patterns while creating struts software.

Some important design patterns are:-

1)      Singleton design pattern (Action servlet)

2)      Front controller (Action Servlet)

3)      Abstract controller (Request Dispatcher)

4)      IOC (inversion of control) (Action Servlet form bean) Dependency injection

5)      V.O.class / D.T.O class (form Bean class)

6)      MVC2 (Whole struts APP)

Resources of Struts 1.x Application – Struts Tutorial

Resources of Struts 1.x Application:-

  1. JSP program -> (view layer)  -> contains presentation logic.
  2. Action servlet -> (controller) -> contains integration logic.
  3. Web XML -> DD file -> contains configurations.
  4. Form beans class -> (controller layer) -> contains form validation logic.
  5. Action class -> (controller / model layer) -> contains Business logic & persistence logic (for other logic)
  6. Struts configuration file -> (XML file) -> controller layer
  7. Action forwards -> points to result pages.

The controller servlet program in struts application is action servlet. It is a built in servlet supplied by struts application.

Note:- except action servlet the remaining all the resources in struts 1.x application must be developed manually.

The Struts JSP programs:-

  • The presentation logic of these JSP programs generates user interface and also formats the results generated by business logics. It is always recommended to develop the JSP programs of struts application as java codeless JSP programs. For these it is recommended to use the following tags.
  • JSP tags of JSP technology:- (except script let, expression, declaration tags)
  • JSTL tags
  • Struts supplied JSP tag library tags
  • Custom JSP tags

Note: – Developing JSP program as java codeless JSP program is called as view helper design pattern implementation.

The Struts Action servlet:-

  • A built in controller servlet of every struts application having the capability to generate integration logic dynamically & automatically based on the configuration done in struts configuration file.
  • Action servlet takes struts-configuration XML file of WEB-INF folder as default struts- configuration file.
  • This actionservlet is httpservlet.

The Struts Web xml:-

  • It is called deployment descriptor (D.D) file of any java web application (including struts application).
  • In this file actionservlet, JSP tag library & web come files be configured.
  • Even though A-servlet is built in servlet its configuration in web xml file is mandatory operation.
  • For process of passing the details of certain resource to underlying server s/w or framework s/w or container s/w is called as “Resource configuration” file.

The Struts Form bean class:-

  • It is a programmer supplied java bean class extending form org. apache.struts.action.ActionForm class.
  • Having capability to hold the form data of form page.
  • Actionservlet writes the form data of form page to form bean class and programmer uses this form data to perform the form validations.
  • The predefined Action form class is on abstract class containing no abstract methods.

Question: What is the need of form bean class in struts application:-

A/c to MVC2 architecture the controller servlet is responsible perform form validations. In struts ActionServlet is built in controller servlet. So programmer cannot write form validation logic by editing the source code of ActionServlet.

To overcome above problem ActionServlet writes the receiver form data of form page to the programmer supplied form bean class. So programmer can write his choice of form validation logic in form bean class by using form data.

Form bean class is helper resource to ActionServlet in controller layer.

The Struts Action class:-

  • It is a programmer supplied user –defined java class having ability to act as either model layer resource or controller layer resource.
  • If business logic is directly placed in Action class it comes under model layer resource.
  • If logic is placed in Action class to comm. With other model later resource like ejb component or spring with hibernate app. Then Action class comes under controller layer resource.
  • Every struts action class is a java class extending form org.apache.struts.action.Action class.

Question: what is the need of taking struts action class as controller layer resource:-

  • A/c to MVC2 architecture the controller servlet is responsible for comm. With model layer business component like EIB component spring application spring with hibernate or etc.
  • In struts application ActionServlet is built in controller servlet. So programmer cannot edit the source code of this ActionServlet to place the code of comm. With the above said model layer business component.
  • To overcome these problems ActionServlet uses the support of struts action class to comm. with above said business component. Because Action class is the programmer supplied java class & it can contain logic to comm. With above said business component.

The Struts Struts configuration file:-

  • Any <file name>.xml can be specified as Struts configuration file during ActionServlet configuration in web.xml file.
  • If no file is specified ActionServlet looks to take struts config.xml file of WEB-INF folder as default struts-configure file.
  • This file is heart of the struts app. to provide guidelines & instruction to ActionServlet to generate integration logic dynamically and to decide the flow of execution. This file contains the following configuration.

a)      Form Bean class configuration.

b)      Action classes configuration.

c)       Action forward configuration.

d)      Plug-in configuration.

e)      Properties file configuration etc.

  • Action servlet reads struts-configure file
  • Servlet container reads web.xml file
  • Servlet container is responsible to create & manage form bean, Action class object.

The Struts Action Forwards:-

  • Xml entries in struts configure File pointing to the result pages of Action classes.
  • Action servlet uses these “Action forwards” to decide the result page of Action class to format the result given by Action class. These are controller layers.

Question: Can I write both web.xml & Struts-configuration file related xml entries in a single in a single xml file?

Answer:  Not possible, because these two files (web.xml, Struts-configure file) will not be read by single s/w environment. Actually two predefined s/w environment / resources like servlet container, ActionServlet are reading these two xml files. So they must be in two different files.

Struts 1.x Installation Guide – Struts Tutorial

Struts 1.x Software installation gives:-

  1. Basic framework Software
  2. Plugins-> validator plug-in and  Ties plug-in
  3. Custom JSP tag libraries.
  4. Does about -> API, XML files, JSP tag libraries and etc.
  5. Example application
  6. Jar files representing struts API’s &other helper API’s.
  • Basic framework software contains the logics to generate integration logic of the controller layer dynamically.
  • “Plug-in” is a patch software or s/w application which can enhance the functionalities existing software or software application. In java plug-in come as jar files.
  • JSP tag library contains set of readily available jsp tags. Struts supplies 5 no. of JSP tag libraries have been JSP tags to make programmer developing the JSP programs Of struts application as java codeless JSP programs.
  • Struts home / lib /struts – core – 1.3.8.jar file represents the whole struts API. For this jar file multiple dependent jar files are there.
  • If the classes of a jar file use the classes & interfaces of b-jar file then b-jar file is dependent jar file to a-jar file.
  • Working with struts is nothing but developing web resource programs of normal java web application by taking the support of struts api.
  • Struts api in 3rd party api because it is not part of any java modules like JSE, JEE &JME
  • When java web application uses  3rd party API’s (other than JSE,JEE,JME API’s) then the 3rd party  API related main jar file should be added to class path and 3rd party  API related main jar & dependent jar file should be added to WEB-NF/ lib folder of web application.

First jar (main jar file):-

      Public class demo

             {

                   Public void xyz ()

                      {

                           Test t1=new test (); //initially use class test

                           T1.m1 ();

                     }

            }

Second jar (dependent jar file to first.jar)

      Public class test

         {

               Public class m1

                      {

                         ———–

                        ————

                   }

   }

Development of test app web application:-

      Test srv.java

           Public class testsrv extends httpservlet

               {

                    Public void service (httpservlet request req. httpservlet response res) throws servlet exception, ioexception

             {

                   ————

                    Demo d1=new Demo ();

                    D1.xyz ();

          }

   }

    //assume that sevlet-API.jar is already there is in class path.

Cmd  > javac testsrv.jar (x)

      Error: cannot find symbol demo, xyz

Solution:  add first jar file to class path (“where demo class is available in first.jar”)

cmd> javac testsrv.java -> gives testsrv.class file.

  • Prepare deployment directory structure and deploy the web application in web server.

Give request to testsrv servlet program from browser window…(x)

Exception: java.iang.NoClassDefFound:Demo

Solution: place first.jar file in lib folder of deployed test app web application 

  • Again give request to test servlet program from browser window-> Error come

Exception:  place second.jar file in / lib folder to deployed test app web application. 

  • Give request to TestSrv servlet program from browsers window…(success)

                  —> Response goes to browser window from servlet program.

  • In the above application the jar file added to the class path will be used by java compiler to recognize “demo” class while compiling the servlet program by the jar files placed if in WEB-INF/lib folder will used by servlet container to recognize & use Demo, test classes during the execution of servlet program.
  • Developing struts application is nothing but developing java web application by taking the support of struts API, in the development of web resource programs.

Struts for Beginners – Struts Tutorial

Struts for Beginners:-

  • Struts software is created based on MVC2 architecture /design pattern. Using struts we can develop only MVC2 architecture based java web application and programmer cannot use struts to develop other architecture based web applications.
  • In the process of developing struts application maximum MVC2 principles will be implemented automatically.
  • In struts application development resources, layers are fixed. The comm. between these resources and layers is also fixed. But logics in some of these resources are programmer choice.

Struts Basics:-

  • Type: java based web framework software
  • 1.3. X (compatible with jdk1.4+),  2.1 X (compatible with jdk1.5+)
  • Vender: Apache foundation
  • Open source software
  • Download software as zip file from www.struts.apache.org web site.
  • Extract the zip file to file for installing struts software
  • Creator: Craig mcclanahan
  • For help: www.struts.apache.org, www.forume.apache .org
  • For reference books: Jakarta struts1.x—from O’relly press.
  • Struts 1.x software zip file: struts-1.3.8-all.zip and Struts-1.3.10-all.zip
  • For struts 2.x software zip file: struts-2.1.13-all.zip file.

– Framework software provides abstraction layer on core technologies that means framework software generates the common logics of the same category application & makes app. Developer the application specific logic.
– In this process application development time will be reduced.

Normal Servlets & JSP based MVC2 Architecture Web Application :-

  • View layer->develop all logics manually (presentation logic)
  • Controller layer->develop all logics manually (integration logic & other logic)
  • Model layer->develop all logics manually (B. logic & persistence logic)

Struts based MVC2 Architecture Web Application:-

  • View layer->develop all logics manually 
  • Controller layer->framework s/w generates all logics dynamically
  • Model layer->develop all logics manually

Java based Framework Software – Struts Tutorial

Framework:-

  • The basic java, jee concepts are called as core technologies. They are like servlet jdbc,jsp and etc.
  • Framework is a special software i.e. capable of developing certain architecture based applications having the ability to generate logics certain layer dynamically based on the logics given in other layers.
  • Framework is special software that provides abstraction layer on core technologies and simplifies the process of application development.
  • Abstraction layer makes programmer not worry about underlying poor technologies while developing the applications.
  • Struts is a web framework software providing abstraction layer on servlet-jsp core technologies to develop MVC2 architecture based web applications having the ability to generate integration logic of controller layer dynamically based on the logics given in view layer & model layer.
  • If MVC2 architecture based web application is developed by directly working with core technologies & without using frame work s/w then programmer needs to take care of all the logics of all the layers. In the same application is developed by using web framework s/w like struts then the programmer just needs to take care of view, model layer logics bc3 the framework s/w dynamically generates the controller layer logics. This improves productivity in web application development.  

Java based Framework Software (OAF oracle activation framework):-

1) Web framework software

  1. Struts (a)
  2. JSF (b)
  3. Web work (c)
  4. Spring MVC (d)

2) ORM Framework Software

  1. Hibernate (a)
  2. JDO
  3. Top link (c)
  4. Ibatis (b)

3)  Java-JEE Framework Software

  1. Spring framework software
  2. Spring-interface21 Company
  3. Struts-apache software foundation
  4. Hibernate-red hat
  • Web framework provides abstraction layer on core technologies called servlet, jsp and allows the programmer to develop MVC2 architecture based web application.
  • ORM framework software provide abstraction layer on jdbc & allows developing database software independent persistence logic.
  • Java-JEE framework software provides abstraction layer on multiple java, JEE Core technologies like jdbc  , servlate , jsp , RMI and etc. and allows to develop all kinds of java , JEE application in framework style.
  1. Struts is from apache foundation
  2. JSF is from sun Microsystems
  3. Web work is from open symphony
  4. Spring MVC from interface21
  5. Hibernate from software (red hat)
  6. JDO from apache foundation
  7. Ibatis is from apache foundation
  8. Toplink is from Oracle Corporation
  9. Spring is from interface21.
  • Before the arrival of struts most of the companies used to their company specific framework software’s to develop the web applications.
  • “ASP.net” is a framework i.e. given based on ASP (core technologies) to develop web applications.

MVC2 Architecture in Struts – Struts Tutorial

MVC2 Architecture:-

  • In MVC2 architecture multiple layers will be there representing multiple logics. These multiple logics will be developed by taking the support of multiple technologies.
  • A layer is a logical patrician in the application representing logics.
  • Architecture speaks about arrangement of layers, communication b/w layers towards application development.

Advantages of MVC2:-

  1. Clean separation of logics is possible.
  2. Modification done in logics of one layer does not effect the logics of another layer.
  3. Gives easiness to maintain & enhance the projects.
  4. Parallel development is possible so productivity is good.

How parallel development is possible:-

The project leader divides team into 2 parts

1)      Web authors

2)      JEE developers

  • Web authors use servlet, jsp technology and develops view layer, controller layer logics.
  • JEE developers takes the support of EIB, spring, hibernate, java bean &etc….technologies and develops model layer logics.
  • Since these two part work parallely we can say parallel development is possible.
  • Certain model layer technologies like EJB, spring use built in middle wire services. This reduces burden on the program.

Disadvantages of MVC2 Architecture:-

  • Knowledge on multiple technologies is required.
  • For parallel development multiple programmers are required.
  • While developing MVC2 architecture based web applications we must follow certain rules along with working with multiple technologies having multiple layers .these rules are

1)      Every layer is given to maintain certain logics so place only those logics are suggested to place and do not place any excess logics.

2)      All operations in web application execution must take place under the control of controller servlet.

3)      They can be multiple businesses components in model layer and multiple jsp programs in view layer but their must be only one servlet program in controller layer.

4)      View layer resources & model layer resources must not interact with each other directly they must interact with each other controller servelet.

5)      Two resources of view layer should not interact with each other (jsp programs) directly their most communicate with each other through controller servlet.

Question: The MVC architecture is designed to use certain technologies in each layer can you tell me reasons behind those suggestions?

Question: Can I change the roles of these technologies?

Answer: – Yes, we can change the roles but it is not recommended to do that work.

Reasons:-

If servlet is taken in view layer:-presentation logic of website changes at regular intervals when presentation of logic of servlet is modified programmer need tore-compile the srvlet program &needs to reload the web application.

  • Whereas logics in jsp program can be modified without those recompilation & reloading operations. So jsp are recommended in view layer.

If jsp program is taken as controller:-

To improve readability of jsp the jsp program must be developed as java codeless jsp program (write only tags) but as controller it will be forced to have java code representing integration logic. Bc3 tags are not their to communicate with EJB spring applications of model layer. So take support of servlet program as controller where java code can be added properly without any restrictions for integration logic.

If EJB component/Hibernate app/ spring app is taken as view layer/ controller layer resource…

The above thought itself wrong bc3 view layer, controller layer resources must handle http protocol based request, response but the above applications cannot do that work. So it is recommended to take servlet, jsp programs who can handle http protocol based req. res in controller, view layer.

 If separate servlet program/jsp program is taken in model layer as business component:-

  • The business logic placed in servlet/jsp program.

a)      Specific to current web application(not reusable)

b)      Allows only http request based clients.

c)       Force the programmer to develop some middleware services manually

  • To overcome these problems use EJB component, spring app, spring with hibernate app to develop model layer logics.
  • Design pattern is set of rules which come as best solution for re-occurring problems of application development.
  • Design pattern are given to develop s/w applications by using software technologies much effectively.
  • Design patterns are best practices that are noticed by senior developer to solve problems in application development.
  • Programmer should implement design pattern in coding phase of project development.

Example: – singleton java class, factory method, dao, MVC2 and etc

  • The worst solution for re occurring problem is called as “anti pattern”
  • Initially MVC2 pattern is design pattern to solve the problems of regular web application development. Later it as become architecture based on its popularity of developing web application & creating new s/w technologies like struts, JSF and etc.

Difference between MVC1 and MVC2 in Struts – Struts Tutorial

Difference b/w MVC1 & MVC2:-

  • In MVC1-> same resource (like servlet program or JSP program) contains view layer, controller layer logics but model layer logics will be placed separately.
  • In MVC2-> different resources will be taken for different layers; i.e. for every layer of web application separate resource will be taken.
  • Use MVC1 or MVC2 architectures to overcome the problems of model1 architecture.
  • Model 1 architecture is suitable for small scale web application.
  • MVC1 architecture is suitable for medium scale web application.
  • MVC2 architecture is   suitable for medium scale and large scale web application. 
  • Compare to model 1 architecture MVC1 architecture gives clean  separation of logics but to get more clean separation of logic prefer working with MVC2 architecture.
  • The projects that are developed by using old technologies or out dated technologies or old versions of existing technologies are called as “legacy projects”.

Model1 Architecture Based Web Application Development – Struts Tutorial

Model 1 architecture based web application development:- 

  • In model 1 Architecture  Based web application development if servlet programs are used as server side programs the jsp programs will not be placed in that web application and vice versa. In this process in every servlet program/jsp program multiple logics will be placed as shown above.
  • In this model 1 Architecture  The servlet program or jsp program contains multiple logic’s due to this the following disadvantages are there.

1)      There are no clean separations of logics.

2)      Modification dine in one logic may affect other logics.

3)      Maintenance & enhancement of the web application becomes complex process.

4)      Parallel development is not possible so the productivity is very poor.

Note: –   doing more work in less time with good accuracy is called as “good productivity”

  • Few middleware services should be implemented by the programmer manually. This increases burden on the programmer.

Advantages of Model1 Architecture:-

1)      Knowledge on either servlet or jsp is enough to develop web applications.

2)      Multiple programmers are not required since the parallel development is not possible.

Understanding MVC:-

M->Model-> business logic + persistence logic

  • It is like account officer.
  • Use java class or java bean or EIB component or spring app. Or spring with hibernate app To develop these logic.

V-> view layer->contains presentation logic

  • it is like beautician.
  • Use jsp programs or jtml programs or velocity programs or free marker programs to write this logics.

C->controller layer-> contains integration logic technically called as connectivity

  •  It is like supervisor or traffic police.
  •  Use servlet program or servlet filter program to write these logics.

Integrity logic:-

  • The logic that controls & monitors every operation of the web app. Execution is called integration logic.
  • The integration logic of controller layer takes request from browser window
    • Passes the request to appropriate model layer program—collect the results from model layer program—passes the result to view layer program.
    • Each layer is a logical partition in web application
    • In MVC1, MVC2 arch. Multiple layers will be there and logics in these multiple layers will be developed by using multiple technologies.