SlideShare a Scribd company logo
1 of 64
Introduction To Struts


                     By Anup Wadhekar
       @Gracioussoft Technologies,Pune
       E-mail : wadekaranup@gmail.com
 Generic Web Application Architecture
 J2EE Web Application Architecture
       • CGI,Servlets and JSP
       • Model 1 Architecture
       • Model 2 Architecture - MVC
       • MVC with Configurable Controller
 Struts Architecture – First Look
 Struts Framework Components
 Struts Request Lifecycle
 Struts ‘Simple Hello World’ Example in Eclipse
Generic Web Application Architecture
Components of Generic Web Application
  Client: Generally a browser(user agent) is controlled by a user to operate the Web
   application. The client’s functionality can be expanded by installing plug-in sandapplets.
  Firewall: A piece of software regulating the communication between insecure networks
   (e.g.,the Internet)and secure networks(e.g.,corporate LANs). This communication is
   filtered by access rules.
  Proxy: A proxy is typically used to temporarily store Web pages in a cache. However
   , proxies can also assume other functionalities, e.g., adapting the contents for users
   (customization), or user tracking.
  Web server :A Web server is a piece of software that supports various Web protocols
   like HTTP and HTTPS, etc., to process client requests.
  Database server: This server normally supplies an organization’s production data in
   structured form ,e.g., in tables.
  Media server: This component is primarily used for content streaming of non-
   structured bulk data(e.g.,audio or video).
  Content management server: Similar to a database server, a content management
   server holds contents to serve an application. These contents are normally available in
   the form of semi-structured data ,e.g., XML documents.
  Application server: An application server holds the functionality required by several
   applications, e.g., workflow or customization.
  Legacy application: A legacy application is an older system that should be integrated as
   an internal or external component.
J2EE Web Application Architecture
Why J2EE ?
Technical Benefits

• Enables component based approach to develop enterprise web application.
• Reduces cost and complexity of developing large,multi-tier-web-based
  application.
• Component types supported,State management,Database caching,declarative
   (automated) persistance,scalability through load balancing.

Buisness Benefits

•Indusrty buy-in and choice of vendors,greater utilization of existing IT assets.
• Faster response to change,choice of proven ,scalable and reliable platform.
Components of J2EE Web Application

Client Tier




• Client tier supports both applet container and application client container.
• Applet container is the container to manage the execution of applets.Exam-
 -ples of an applet container are applet viewer,web browser and java Plug-in
  running on the client together.
• Application client container is the one which is responsible for managing the
application client components. Both application client and its container resides
at the client machine and are executed on the client end. Example of
application container is JVM.
Components of J2EE Web Application
                            Middle Tier
• Whole presentation and buisness logic is executed in middle tier which con-
 sists of Web container , EJB container and a number of industry standered APIs
 for accessing Enterprise Information system and Database.

• EJB Container
  Enterprise Java Beans (EJB) is a tecnology in J2EE platform,which standerdizes
  how to build server side components for distributed applications.It is a reusa-
  ble software components written in java,which run inside EJB Container.EJB
container is a part of J2EE application server which manages whole lifecycle of
 EJBs and provide them with some important system level services.When client
 sends request through JSP,JSP request EJB for information.Once EJB generate
 Information from database,JSP file then display it to client.
                   EJB is NOT relevant to our discussion to Struts.
Components of J2EE Web Application
                           Middle Tier
• Web Container
In Web Container also known as Servlet container,JSPs and Servlets are main
non-pure java components mixed with plain static pages.They can also
generate dynamic HTML with dynamic contents coming from back end tier and
interact with client-tier components.
  In J2EE platform,the presentation between end user and system response
should be handled by JSP and Servlets technologies and buisness logic should
be encapsulated by Java Bean (or Enterprise Java Bean).

•Industry Standerd APIs are for accessing Enterprise Information system and
Database. They include following services : 1)HTTP,HTTPs 2)Java Transaction
 API(JTA) 3)Java Interface Definition Language(JavaIDL) 4)Java Naming and
Directory Services (JNDI) 5)Java Message Services (JMS) 6)RMI-IIOP etc.
Components of J2EE Web Application

• Java EE Containers
1) Application client container
2) Applet Container
3) Web container – part of Java EE Application Server
4) EJB Container - part of Java EE Application Server
All of the above comes under Java EE Containers.

• Java EE Application Servers

 J2EE specification defines a whole lot of interfaces and a few
 classes.Implementations for these interfaces adhering to the J2EE
 specifications. These implementations are called J2EE Application
 Servers.
 Example : WebLogic by Oracle,WebSphere by IBM,Gerinomo,TomEE
 by Apache,Jboss etc
CGI ,SERVLET AND JSP

Evolution of Dynamic Content Generation
When World Wide Web (WWW) started in the year 1989 at he CERN laboratory
the idea was to have a mechanism which enabled sharing of research
information among researchers using hypertext docs. And hence Web was
designed to serve static contents in the beginning. The obvious and natural
progression was to have the ability of dynamic content generation on Web and
there came the concept of CGI.

CGI - Common Gateway Interface
CGI was designed to generate the contents on the Web dynamically. It became
hugely popular in no time as it allowed the Web applications to access the
database to show results based on dynamically selected criterio and it also
facilitated insert/update of information in the database accepting the info from
the end-user.As the popularity grew the scalability of the web applications also
grew and then we started realizing the limitaions of CGI.
CGI ,SERVLET AND JSP

Limitations of CGI

New Process per Request - the main drawback of CGI approach was that it
spawned a new heavy-weight Operating System process everytime a new
request was made from the end users (from browser). This immensely
restricted the scalability and responsiveness of the web applications as creating
(and reclaiming once the request is served) OS processes are time and resource
consuming stuff.Communication Gap between Web Server and Requests - since
all the requests are executed in a different OS process from the Web Server
process hence it becomes difficult to have a smooth communication between
the server and the requests to handle stuff like logging, authorization, etc.

Alternatives of CGI FastCGI,mod_perl,NSAPI,ISAPI Most important and
Popular one :Java Servlets
CGI ,SERVLET AND JSP

Java Servlets - what are they?
Sun Microsystems introduced this technology in the year 1997 and it became an instant hit
due to various advantages it provided over CGI. It was no longer required to have a new
process every time a request was made from an end-user.




It was a platform-independent (As it is written completely in Java), component-based
approach of developing web applications having dynamic content genration capabilities.
Since it is written in Java hence all the tested and tried rich set of APIs of Java are readily
available to be used and this advantage took this technology way above its competitors.
CGI ,SERVLET AND JSP

            Example Servlet Code
CGI ,SERVLET AND JSP

J2EE Web Application

Any web application that runs in the servlet container is called a J2EE web
application. The servlet container implements the Servlet and JSP specification.
It provides various entry points for handling the request originating from a web
browser. There are three entry points for the browser into the J2EE web
application - Servlet, JSP and Filter. You can create your own Servlets by
extending the javax.servlet.http.HttpServlet class and implementing
the doGet() and doPost() method. You can create JSPs simply by creating a
text file containing JSP markup tags. You can create Filters by implementing the
javax.servlet.Filter interface.
The servlet container becomes aware of Servlets and Filters when they are
declared in a special file called web.xml . A J2EE web application has exactly
One web.xml.
CGI ,SERVLET AND JSP

Why were JSPs needed when we had Servlets?
Servlet Drawbacks
Servlets do an excellent job of dynamic content generation, but it becomes difficult and
tedious to use Servlets for presentation of the data in HTML. EVery HTML change requires
us to recompile the Servlet and the maintenance of Servlets become difficult as HTML
changes are quite frequest in nature and using Servlets to do that ends up making
corresponding Java code changes everytime.
Another serious drawback of this approach was that it didn't facilitate clear separation
of roles and responsibilities. HTML design and devlopment is primarily the responsibility
of a Web Designer (usually a person having limited Java expertise) whereas the
responsibility of design & development of Servlets belongs to Java Developers. Using
Servlets for presentaion of data mixed both these roles and hence the entire devlopment
life cycle used to be more complex and hence slower. A clear separation of roles and
responsibilities enhanced the overall development cycle and it also made the applications
better maintainable.
CGI ,SERVLET AND JSP

Java Server Pages (JSP) Technology

JSP (JavaServer Pages) Technology is used to achieve the clear separation. A JSP
can use normal HTML tags/elements the way we can have in any other normal
HTML file and in addition it can have Tags, Scriptlets, etc. to encapsulate the
business logic for the dynamic content generation. A Web Designer can simply
use those tags or leave the scriptlets to be embedded by the Java Developers. In
fact, it's become a better practice to avoid scriptlets as much as we can from a
JSP page and to rely only on Tags for the dynamic content generation. This not
only makes the life of JSP Page easier, but also enhances the reusability of the
code (writen for Tags) and hence improves maintanability.

There are two models for developing JSP based web application architectures.
• Model 1 Architecture
• Model 2 Architecture (MVC)
Model 1 Architecture
Model 1 Architecture – How it Works

     In this architecture a JSP Page is used not only for the display of the output to the
      client, but also for the entire request processing including Accepting the
      Request, Creating JavaBeans (or connecting to the DB for data), Executing the
      Business Logic to generate Dynamic Content, etc


     Let us illustrate the operation of Model 1 architecture with an example.
      Consider a HTML page with a hyperlink to a JSP. When user clicks on the
      hyperlink, the JSP is directly invoked. This is shown in Figure 1.1. The servlet
      container parses the JSP and executes the resulting Java servlet. The JSP contains
      embedded code and tags to access the Model JavaBeans. The Model JavaBeans
      contains attributes for holding the HTTP request parameters from the query
      string. In addition it contains logic to connect to the middle tier or directly to the
      database using JDBC to get the additional data needed to display the page. The
      JSP is then rendered as HTML using the data in the Model JavaBeans and other
      Helper classes and tags.
Model 1 Architecture – Disadvantages

     There is some separation between content (Model JavaBeans) and presentation
      (JSP). This separation is good enough for smaller applications. Larger applications
      have a lot of presentation logic.


     The presentation logic usually leads to a significant amount of Java code
      embedded in the JSP in the form of scriptlets. This is ugly and maintenance
      nightmare even for experienced Java developers.


     In large applications, JSPs are developed and maintained by page authors.
      The intermingled scriptlets and markup results in unclear definition of roles
      and is very problematic.


     Application control is decentralized in Model 1 architecture since the next
      page to be displayed is determined by the logic embedded in the current
      page.Decentralized navigation control can cause headaches. All this leads us
      to Model 2 architecture .
Restaurant – Analogy (Single Employee)
It’s like coding everything in single servlet !
Restaurant – Analogy (multiple employee)
That sounds like MVC !
Model 2 Architecture - MVC
Model 2 Architecture – How it Works
   The main difference between Model 1 and Model 2 is that in Model 2, a
   controller handles the user request instead of another JSP. The controller is
   implemented as a Servlet. The following steps are executed when the user
   submits the request.

   1. The Controller Servlet handles the user’s request. (This means the hyperlink
   in the JSP should point to the controller servlet).
   2 .The Controller Servlet then instantiates appropriate JavaBeans based on the
   request parameters (and optionally also based on session attributes).
   3 .The Controller Servlet then by itself or through a controller helper
   communicates with the middle tier or directly to the database to fetch the
   required data.
   4 . The Controller sets the resultant JavaBeans (either same or a new one) in
   one of the following contexts – request, session or application.
   5 . The controller then dispatches the request to the next view based on the
   request URL.
   6. The View uses the resultant JavaBeans from Step 4 to display data.
Model 2 Architecture – How it Works
   The main difference between Model 1 and Model 2 is that in Model 2, a
   controller handles the user request instead of another JSP. The controller is
   implemented as a Servlet. The following steps are executed when the user
   submits the request.

   1. The Controller Servlet handles the user’s request. (This means the hyperlink
   in the JSP should point to the controller servlet).
   2 .The Controller Servlet then instantiates appropriate JavaBeans based on the
   request parameters (and optionally also based on session attributes).
   3 .The Controller Servlet then by itself or through a controller helper
   communicates with the middle tier or directly to the database to fetch the
   required data.
   4 . The Controller sets the resultant JavaBeans (either same or a new one) in
   one of the following contexts – request, session or application.
   5 . The controller then dispatches the request to the next view based on the
   request URL.
   6. The View uses the resultant JavaBeans from Step 4 to display data.
Model 2 Architecture – Advantages

      No presentation logic in JSP, there are no scriptlets. This means
       lesser nightmares,although MVC does not architecturally prevent you from
       adding scriptlets.

      With MVC you can have as many controller servlets in your web application, one
       Controller Servlet per module.

     A single controller servlet for the web application lets you centralize all the
      tasks in a single place,avoids duplication of code.


      Web applications based on Model 2 architecture are easier to maintain and
       extend since the views do not refer to each other and there is no presenta-
       -ion logic in the views.

     It also allows you to clearly define the roles and responsibilities in large
      projects thus allowing better coordination among team members.
Model 2 Architecture – Disadvantages
 Controller gone bad – Fat Controller

   If MVC is all that great, why do we need Struts after all? The answercomplexities.
    the difficulties associated in applying bare bone MVC to real world
                                                                          lies in

     In medium to large applications, centralized control and processing logic in the
     servlet – the greatest plus of MVC is also its weakness.

    Consider a mediocre application with 15 JSPs. Assume that each page has five
     hyperlinks (or five form submissions). The total number of user requests to be
     handled in the application is 75. Since we are using MVC framework, a centralized
     controller servlet handles every user request. For each type of incoming request
     there is “if” block in the doGet method of the controller Servlet to process the
     request and dispatch to the next view. For this mediocre application of ours, the
     controller Servlet has 75 if blocks. Even if you assume that each if block delegates
     the request handling to helper classes it is still no good. You can only imagine how
     bad it gets for a complex enterprise web application. So, we have a problem at
     hand. The Controller Servlet that started out as the greatest thing next to sliced
     bread has gone bad. It has put on a lot of weight to become a Fat Controller.
MVC with Configurable Controller
Configurable Controller Servlet Code

               Example Servlet Code
MVC with Configurable Controller
 How It works
 1. Properties file :It contains information in key value pair which is actually
 one to one mapping URL for each http request and handler class. There is a
 unique handler class for each url.
 2 . Controller Servlet loads the properties file on startup
 3 . When the HTTP request arrives from the client, the Controller Servlet looks
 up in a properties file to decide on the right Handler class for the HTTP
 request.This Handler class is referred to as the Request Handler.
 4 . The Request Handler contains the presentation logic for that HTTP request
 including business logic invocation. In other words, the Request Handler does
 everything that is needed to handle the HTTP request.
 5 . The only difference so far from the bare bone MVC is that the controller
 servlet looks up in a properties file to instantiate the Handlerinstead of calling
 it directly.
MVC with Configurable Controller

6. there must be some sort of commonality between the Request Handlers
for the servlet to generically instantiate the Request Handler. The commonal-
-ity is that all Request Handler classes implement a common interface. Let us
call this common interface as Handler Interface. In its simplest form, the
Handler Interface has one method say, execute().
7 . The Controller Servlet instantiates the Request Handler in the doGet()
method and invokes the execute() method on it using Java Reflection. The
execute() method invokes appropriate business logic from the middle tier and
then selects the next view to be presented to the user.
8 . The controller servlet forwards the request to the selected JSP view. All this
happens in the doGet() method of the controller servlet. The doGet() method
lifecycle never changes.What changes is the Request Handler’s execute()
method.
9. You just saw how Struts works in a nutshell!!! Instead of using a properties
file like we did in this example, Struts uses XML to store more useful
information.
Struts Architecture – First Look
Struts Framework Components

1. All the core components of Struts framework belong to
Controller category.

2. Struts has no components in the Model category.

3. Struts has only auxiliary components in View category. A
collection of custom tags making it easy to interact with the
controller. The View category is neither the core of Struts
framework nor is it necessary.However it is a helpful library for
using Struts effectively in JSP based rendering.
Struts Framework Components
Controller Category
The ActionServlet and the collaborating classes form the controller
and is the core of the framework. The collaborating classes are :
1.RequestProcessor
2.ActionForm
3.Action
4.ActionMapping
5 .Action Forward.

View Category
It contains utility classes – variety of custom tags making it easy
to interact with the controller. It is not mandatory to use these
utility classes. You can replace it with classes of your own.
Struts Framework Components
Model Category

Struts does not offer any components in the Model Category.Many
component models (CORBA, EJB) are available to implement the
business tier.

NOTE: Some people argue that ActionForm is the model component.
However ActionForm is really part of the controller. The Struts
documentation also speaks along similar lines. It is just View Data
Transfer Object – a regular JavaBeans that has dependencies on the
Struts classes and used for transferring the data to various classes
within the controller.
Struts Request Lifecycle
A request from the client browser creates an HTTP request which comes to the servlet
container.
Step 1 :
Servlet container looks up into web.xml,using load-on-startup Instantiate the
ActionServlet and do following three tasks:
First Task : The ActionServlet takes the Struts Config file name as an init-param.
At startup, in the init() method, the ActionServlet reads the Struts Config file and load
into memory.
Struts Request Lifecycle
Second Task : If the user types http://localhost:8080/app/submitForm.do in
the browser URL bar, the URL will be intercepted and processed by the
ActionServlet since the URL has a pattern *.do, with a suffix of "do".
Because servlet-mapping is

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

Third Task : Then ActionServlet delegates the request handling to another
class called RequestProcessor by invoking
its process() method.
Struts Request Lifecycle
Step 2 :

The RequestProcessor does the following in its process() method
a) The RequestProcessor looks up the configuration file for the URL pattern
/submitForm (if the URL is http://localhost:8080/app/submitForm.do). and
and finds the XML block (ActionMapping).

ActionMapping from struts-config.xml
Struts Request Lifecycle
b) The RequestProcessor instantiates the EmpForm and puts it in appropriate
scope – either session or request.The RequestProcessor determines the
appropriate scope by looking at the scope attribute in the same ActionMapping.
c) RequestProcessor iterates through the HTTP request parameters and populates
the EmpForm.
d) the RequestProcessor checks for the validateattribute in the ActionMapping.
If the validate is set to true, the RequestProcessor invokes the validate() method
on the EmpForm instance.
This is the method where you can put all the html form data validations.
If Validate fail the RequestProcessor looks for the input attribute and return to JSP
page mentioned in input tag.
If Validate pass goto next step.
e) The RequestProcessor instantiates the Action class specified in the
ActionMapping (EmpAction) and invokes the execute() method on the EmpAction
instance.
Struts Request Lifecycle
Signature of the execute method :




f)Association of the logical name and the physical JSP page is encapsulated in the
ActionForward instance returned from the execute method.
In return mapping.findForward("success") RequestProcessor looks for the success
attribute and forward to JSP page mentioned in success tag. i.e success.jsp.
In return mapping.findForward("failure")
RequestProcessor looks for the failure attribute and forward to JSP page mentioned in
failure tag. i.e. failure.jsp
In J2EE terms, this is referred to as dispatching the view to the user.
‘Simple Hello World’ Example
 Requirements :
 Softwares
 1. Eclipse IDE    http://www.eclipse.org/downloads/
 2. Tomcat Server   http://tomcat.apache.org/download-60.cgi
 3. JDK www.oracle.com/technetwork/java/javase/downloads/index.html

 Libraries Struts 1.3                   FILES

                                    XML                   Java
                                    1.web.xml           1.HelloWorldAction.java
                                    2.struts-config.xml 2.HelloWorldForm.java
                                    JSP
                                    1.HelloWorld.jsp
                                    2.index.jsp
                                    3.failure.jsp
http://struts.apache.org/download.cgi
Dynamic Web Project – Directory Structure
web.xml
struts-config.xml
HelloWorldAction.java
HelloWorldForm.java
HelloWorldForm.java
index.jsp
HelloWorld.jsp
failure.jsp
STEPS TO EXECUTE

  1. Create dynamic web project in eclipse
  2. Add jsp,xml and java files according to directory structure.
  3. Add struts libraries in Web-INF/lib folder.
  4. Add same struts libraries in java build path(Right click on main
     project ->properties->java build path->libraries ->add external
     jar
  5. Add tomcat server (Windows menu -> show view ->servers ->OK
  6. Go to server wizard -> add new server - >Apache -> select the
     tomcat version you downloaded ->Next ->Browse ->select the
     folder where you extracted or installed the downloaded
     tomcat ->finish
  7. After adding server,right click on Project-> Run as -> Run on
     Server ->select server you added ->Finish
First run – On Startup
Type ‘HelloWorld.do’ in url - Run
return mapping.findForward(“failure”)
THANK YOU !!!




F EEDBACK : WADEKARANUP @ GMAIL . COM

More Related Content

What's hot

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
J2EE Architecture Explained
J2EE  Architecture ExplainedJ2EE  Architecture Explained
J2EE Architecture ExplainedAdarsh Kr Sinha
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1Д. Ганаа
 
Ibm web sphere_job_interview_preparation_guide
Ibm web sphere_job_interview_preparation_guideIbm web sphere_job_interview_preparation_guide
Ibm web sphere_job_interview_preparation_guideKhemnath Chauhan
 
IBM Websphere introduction and installation for beginners
IBM Websphere introduction and installation for beginnersIBM Websphere introduction and installation for beginners
IBM Websphere introduction and installation for beginnersShubham Gupta
 
Summer training java
Summer training javaSummer training java
Summer training javaArshit Rai
 
J2 ee architecture
J2 ee architectureJ2 ee architecture
J2 ee architectureKrishna Mer
 
Summer training java
Summer training javaSummer training java
Summer training javaArshit Rai
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsKaml Sah
 
Ibm web sphere application server interview questions
Ibm web sphere application server interview questionsIbm web sphere application server interview questions
Ibm web sphere application server interview questionspraveen_guda
 
Websphere interview Questions
Websphere interview QuestionsWebsphere interview Questions
Websphere interview Questionsgummadi1
 
Spring intro classes-in-mumbai
Spring intro classes-in-mumbaiSpring intro classes-in-mumbai
Spring intro classes-in-mumbaivibrantuser
 

What's hot (19)

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Suresh Resume
Suresh ResumeSuresh Resume
Suresh Resume
 
J2EE Architecture Explained
J2EE  Architecture ExplainedJ2EE  Architecture Explained
J2EE Architecture Explained
 
Spring
SpringSpring
Spring
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
 
Servlet programming
Servlet programmingServlet programming
Servlet programming
 
Ibm web sphere_job_interview_preparation_guide
Ibm web sphere_job_interview_preparation_guideIbm web sphere_job_interview_preparation_guide
Ibm web sphere_job_interview_preparation_guide
 
Jdbc
JdbcJdbc
Jdbc
 
IBM Websphere introduction and installation for beginners
IBM Websphere introduction and installation for beginnersIBM Websphere introduction and installation for beginners
IBM Websphere introduction and installation for beginners
 
Enterprise java beans
Enterprise java beansEnterprise java beans
Enterprise java beans
 
Summer training java
Summer training javaSummer training java
Summer training java
 
IBM WebSphere Portal
IBM WebSphere PortalIBM WebSphere Portal
IBM WebSphere Portal
 
J2 ee architecture
J2 ee architectureJ2 ee architecture
J2 ee architecture
 
Summer training java
Summer training javaSummer training java
Summer training java
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 
Ibm web sphere application server interview questions
Ibm web sphere application server interview questionsIbm web sphere application server interview questions
Ibm web sphere application server interview questions
 
Websphere interview Questions
Websphere interview QuestionsWebsphere interview Questions
Websphere interview Questions
 
Spring intro classes-in-mumbai
Spring intro classes-in-mumbaiSpring intro classes-in-mumbai
Spring intro classes-in-mumbai
 

Viewers also liked

Analysis bottleneck in J2EE application
Analysis bottleneck in J2EE applicationAnalysis bottleneck in J2EE application
Analysis bottleneck in J2EE applicationTerry Cho
 
Presentation d'un logiciel de GRH
Presentation d'un logiciel de GRHPresentation d'un logiciel de GRH
Presentation d'un logiciel de GRHRiadh K.
 
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...Riadh K.
 
présentation soutenance PFE.ppt
présentation soutenance PFE.pptprésentation soutenance PFE.ppt
présentation soutenance PFE.pptMohamed Ben Bouzid
 

Viewers also liked (6)

Analysis bottleneck in J2EE application
Analysis bottleneck in J2EE applicationAnalysis bottleneck in J2EE application
Analysis bottleneck in J2EE application
 
Spring Ldap
Spring LdapSpring Ldap
Spring Ldap
 
Presentation d'un logiciel de GRH
Presentation d'un logiciel de GRHPresentation d'un logiciel de GRH
Presentation d'un logiciel de GRH
 
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
 
Présentation Projet de fin d'études
Présentation Projet de fin d'étudesPrésentation Projet de fin d'études
Présentation Projet de fin d'études
 
présentation soutenance PFE.ppt
présentation soutenance PFE.pptprésentation soutenance PFE.ppt
présentation soutenance PFE.ppt
 

Similar to Intorduction to struts

Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music storeADEEBANADEEM
 
J2 EEE SIDES
J2 EEE  SIDESJ2 EEE  SIDES
J2 EEE SIDESbputhal
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...WebStackAcademy
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxkarthiksmart21
 
Enterprise application developement
Enterprise application developementEnterprise application developement
Enterprise application developementArchana Jha
 
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCJ2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCChaithraCSHirematt
 
Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01Prashanth Shivakumar
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year projectsuneel singh
 
Web programming and development - Introduction
Web programming and development - IntroductionWeb programming and development - Introduction
Web programming and development - IntroductionJoel Briza
 
Web Logic Jboss Final
Web Logic Jboss FinalWeb Logic Jboss Final
Web Logic Jboss FinalMohamed Atef
 

Similar to Intorduction to struts (20)

Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
J2 EEE SIDES
J2 EEE  SIDESJ2 EEE  SIDES
J2 EEE SIDES
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Java EE 7 introduction
Java EE 7  introductionJava EE 7  introduction
Java EE 7 introduction
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
 
Java part 3
Java part  3Java part  3
Java part 3
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
Enterprise application developement
Enterprise application developementEnterprise application developement
Enterprise application developement
 
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCJ2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
 
4. J2EE.pptx
4. J2EE.pptx4. J2EE.pptx
4. J2EE.pptx
 
Enterprice java
Enterprice javaEnterprice java
Enterprice java
 
Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
 
J2EE day 1
J2EE day 1J2EE day 1
J2EE day 1
 
J2 ee architecture
J2 ee architectureJ2 ee architecture
J2 ee architecture
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
 
Servlet programming
Servlet programmingServlet programming
Servlet programming
 
Web programming and development - Introduction
Web programming and development - IntroductionWeb programming and development - Introduction
Web programming and development - Introduction
 
Web Logic Jboss Final
Web Logic Jboss FinalWeb Logic Jboss Final
Web Logic Jboss Final
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

Intorduction to struts

  • 1. Introduction To Struts By Anup Wadhekar @Gracioussoft Technologies,Pune E-mail : wadekaranup@gmail.com
  • 2.  Generic Web Application Architecture  J2EE Web Application Architecture • CGI,Servlets and JSP • Model 1 Architecture • Model 2 Architecture - MVC • MVC with Configurable Controller  Struts Architecture – First Look  Struts Framework Components  Struts Request Lifecycle  Struts ‘Simple Hello World’ Example in Eclipse
  • 3.
  • 4. Generic Web Application Architecture
  • 5. Components of Generic Web Application  Client: Generally a browser(user agent) is controlled by a user to operate the Web application. The client’s functionality can be expanded by installing plug-in sandapplets.  Firewall: A piece of software regulating the communication between insecure networks (e.g.,the Internet)and secure networks(e.g.,corporate LANs). This communication is filtered by access rules.  Proxy: A proxy is typically used to temporarily store Web pages in a cache. However , proxies can also assume other functionalities, e.g., adapting the contents for users (customization), or user tracking.  Web server :A Web server is a piece of software that supports various Web protocols like HTTP and HTTPS, etc., to process client requests.  Database server: This server normally supplies an organization’s production data in structured form ,e.g., in tables.  Media server: This component is primarily used for content streaming of non- structured bulk data(e.g.,audio or video).  Content management server: Similar to a database server, a content management server holds contents to serve an application. These contents are normally available in the form of semi-structured data ,e.g., XML documents.  Application server: An application server holds the functionality required by several applications, e.g., workflow or customization.  Legacy application: A legacy application is an older system that should be integrated as an internal or external component.
  • 6.
  • 7. J2EE Web Application Architecture
  • 8. Why J2EE ? Technical Benefits • Enables component based approach to develop enterprise web application. • Reduces cost and complexity of developing large,multi-tier-web-based application. • Component types supported,State management,Database caching,declarative (automated) persistance,scalability through load balancing. Buisness Benefits •Indusrty buy-in and choice of vendors,greater utilization of existing IT assets. • Faster response to change,choice of proven ,scalable and reliable platform.
  • 9. Components of J2EE Web Application Client Tier • Client tier supports both applet container and application client container. • Applet container is the container to manage the execution of applets.Exam- -ples of an applet container are applet viewer,web browser and java Plug-in running on the client together. • Application client container is the one which is responsible for managing the application client components. Both application client and its container resides at the client machine and are executed on the client end. Example of application container is JVM.
  • 10. Components of J2EE Web Application Middle Tier • Whole presentation and buisness logic is executed in middle tier which con- sists of Web container , EJB container and a number of industry standered APIs for accessing Enterprise Information system and Database. • EJB Container Enterprise Java Beans (EJB) is a tecnology in J2EE platform,which standerdizes how to build server side components for distributed applications.It is a reusa- ble software components written in java,which run inside EJB Container.EJB container is a part of J2EE application server which manages whole lifecycle of EJBs and provide them with some important system level services.When client sends request through JSP,JSP request EJB for information.Once EJB generate Information from database,JSP file then display it to client. EJB is NOT relevant to our discussion to Struts.
  • 11. Components of J2EE Web Application Middle Tier • Web Container In Web Container also known as Servlet container,JSPs and Servlets are main non-pure java components mixed with plain static pages.They can also generate dynamic HTML with dynamic contents coming from back end tier and interact with client-tier components. In J2EE platform,the presentation between end user and system response should be handled by JSP and Servlets technologies and buisness logic should be encapsulated by Java Bean (or Enterprise Java Bean). •Industry Standerd APIs are for accessing Enterprise Information system and Database. They include following services : 1)HTTP,HTTPs 2)Java Transaction API(JTA) 3)Java Interface Definition Language(JavaIDL) 4)Java Naming and Directory Services (JNDI) 5)Java Message Services (JMS) 6)RMI-IIOP etc.
  • 12. Components of J2EE Web Application • Java EE Containers 1) Application client container 2) Applet Container 3) Web container – part of Java EE Application Server 4) EJB Container - part of Java EE Application Server All of the above comes under Java EE Containers. • Java EE Application Servers J2EE specification defines a whole lot of interfaces and a few classes.Implementations for these interfaces adhering to the J2EE specifications. These implementations are called J2EE Application Servers. Example : WebLogic by Oracle,WebSphere by IBM,Gerinomo,TomEE by Apache,Jboss etc
  • 13.
  • 14. CGI ,SERVLET AND JSP Evolution of Dynamic Content Generation When World Wide Web (WWW) started in the year 1989 at he CERN laboratory the idea was to have a mechanism which enabled sharing of research information among researchers using hypertext docs. And hence Web was designed to serve static contents in the beginning. The obvious and natural progression was to have the ability of dynamic content generation on Web and there came the concept of CGI. CGI - Common Gateway Interface CGI was designed to generate the contents on the Web dynamically. It became hugely popular in no time as it allowed the Web applications to access the database to show results based on dynamically selected criterio and it also facilitated insert/update of information in the database accepting the info from the end-user.As the popularity grew the scalability of the web applications also grew and then we started realizing the limitaions of CGI.
  • 15. CGI ,SERVLET AND JSP Limitations of CGI New Process per Request - the main drawback of CGI approach was that it spawned a new heavy-weight Operating System process everytime a new request was made from the end users (from browser). This immensely restricted the scalability and responsiveness of the web applications as creating (and reclaiming once the request is served) OS processes are time and resource consuming stuff.Communication Gap between Web Server and Requests - since all the requests are executed in a different OS process from the Web Server process hence it becomes difficult to have a smooth communication between the server and the requests to handle stuff like logging, authorization, etc. Alternatives of CGI FastCGI,mod_perl,NSAPI,ISAPI Most important and Popular one :Java Servlets
  • 16. CGI ,SERVLET AND JSP Java Servlets - what are they? Sun Microsystems introduced this technology in the year 1997 and it became an instant hit due to various advantages it provided over CGI. It was no longer required to have a new process every time a request was made from an end-user. It was a platform-independent (As it is written completely in Java), component-based approach of developing web applications having dynamic content genration capabilities. Since it is written in Java hence all the tested and tried rich set of APIs of Java are readily available to be used and this advantage took this technology way above its competitors.
  • 17. CGI ,SERVLET AND JSP Example Servlet Code
  • 18. CGI ,SERVLET AND JSP J2EE Web Application Any web application that runs in the servlet container is called a J2EE web application. The servlet container implements the Servlet and JSP specification. It provides various entry points for handling the request originating from a web browser. There are three entry points for the browser into the J2EE web application - Servlet, JSP and Filter. You can create your own Servlets by extending the javax.servlet.http.HttpServlet class and implementing the doGet() and doPost() method. You can create JSPs simply by creating a text file containing JSP markup tags. You can create Filters by implementing the javax.servlet.Filter interface. The servlet container becomes aware of Servlets and Filters when they are declared in a special file called web.xml . A J2EE web application has exactly One web.xml.
  • 19. CGI ,SERVLET AND JSP Why were JSPs needed when we had Servlets? Servlet Drawbacks Servlets do an excellent job of dynamic content generation, but it becomes difficult and tedious to use Servlets for presentation of the data in HTML. EVery HTML change requires us to recompile the Servlet and the maintenance of Servlets become difficult as HTML changes are quite frequest in nature and using Servlets to do that ends up making corresponding Java code changes everytime. Another serious drawback of this approach was that it didn't facilitate clear separation of roles and responsibilities. HTML design and devlopment is primarily the responsibility of a Web Designer (usually a person having limited Java expertise) whereas the responsibility of design & development of Servlets belongs to Java Developers. Using Servlets for presentaion of data mixed both these roles and hence the entire devlopment life cycle used to be more complex and hence slower. A clear separation of roles and responsibilities enhanced the overall development cycle and it also made the applications better maintainable.
  • 20. CGI ,SERVLET AND JSP Java Server Pages (JSP) Technology JSP (JavaServer Pages) Technology is used to achieve the clear separation. A JSP can use normal HTML tags/elements the way we can have in any other normal HTML file and in addition it can have Tags, Scriptlets, etc. to encapsulate the business logic for the dynamic content generation. A Web Designer can simply use those tags or leave the scriptlets to be embedded by the Java Developers. In fact, it's become a better practice to avoid scriptlets as much as we can from a JSP page and to rely only on Tags for the dynamic content generation. This not only makes the life of JSP Page easier, but also enhances the reusability of the code (writen for Tags) and hence improves maintanability. There are two models for developing JSP based web application architectures. • Model 1 Architecture • Model 2 Architecture (MVC)
  • 22. Model 1 Architecture – How it Works  In this architecture a JSP Page is used not only for the display of the output to the client, but also for the entire request processing including Accepting the Request, Creating JavaBeans (or connecting to the DB for data), Executing the Business Logic to generate Dynamic Content, etc  Let us illustrate the operation of Model 1 architecture with an example. Consider a HTML page with a hyperlink to a JSP. When user clicks on the hyperlink, the JSP is directly invoked. This is shown in Figure 1.1. The servlet container parses the JSP and executes the resulting Java servlet. The JSP contains embedded code and tags to access the Model JavaBeans. The Model JavaBeans contains attributes for holding the HTTP request parameters from the query string. In addition it contains logic to connect to the middle tier or directly to the database using JDBC to get the additional data needed to display the page. The JSP is then rendered as HTML using the data in the Model JavaBeans and other Helper classes and tags.
  • 23. Model 1 Architecture – Disadvantages  There is some separation between content (Model JavaBeans) and presentation (JSP). This separation is good enough for smaller applications. Larger applications have a lot of presentation logic.  The presentation logic usually leads to a significant amount of Java code embedded in the JSP in the form of scriptlets. This is ugly and maintenance nightmare even for experienced Java developers.  In large applications, JSPs are developed and maintained by page authors. The intermingled scriptlets and markup results in unclear definition of roles and is very problematic.  Application control is decentralized in Model 1 architecture since the next page to be displayed is determined by the logic embedded in the current page.Decentralized navigation control can cause headaches. All this leads us to Model 2 architecture .
  • 24.
  • 25. Restaurant – Analogy (Single Employee)
  • 26. It’s like coding everything in single servlet !
  • 27.
  • 28. Restaurant – Analogy (multiple employee)
  • 30.
  • 32. Model 2 Architecture – How it Works The main difference between Model 1 and Model 2 is that in Model 2, a controller handles the user request instead of another JSP. The controller is implemented as a Servlet. The following steps are executed when the user submits the request. 1. The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet). 2 .The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes). 3 .The Controller Servlet then by itself or through a controller helper communicates with the middle tier or directly to the database to fetch the required data. 4 . The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application. 5 . The controller then dispatches the request to the next view based on the request URL. 6. The View uses the resultant JavaBeans from Step 4 to display data.
  • 33. Model 2 Architecture – How it Works The main difference between Model 1 and Model 2 is that in Model 2, a controller handles the user request instead of another JSP. The controller is implemented as a Servlet. The following steps are executed when the user submits the request. 1. The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet). 2 .The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes). 3 .The Controller Servlet then by itself or through a controller helper communicates with the middle tier or directly to the database to fetch the required data. 4 . The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application. 5 . The controller then dispatches the request to the next view based on the request URL. 6. The View uses the resultant JavaBeans from Step 4 to display data.
  • 34. Model 2 Architecture – Advantages  No presentation logic in JSP, there are no scriptlets. This means lesser nightmares,although MVC does not architecturally prevent you from adding scriptlets.  With MVC you can have as many controller servlets in your web application, one Controller Servlet per module.  A single controller servlet for the web application lets you centralize all the tasks in a single place,avoids duplication of code.  Web applications based on Model 2 architecture are easier to maintain and extend since the views do not refer to each other and there is no presenta- -ion logic in the views.  It also allows you to clearly define the roles and responsibilities in large projects thus allowing better coordination among team members.
  • 35. Model 2 Architecture – Disadvantages Controller gone bad – Fat Controller  If MVC is all that great, why do we need Struts after all? The answercomplexities. the difficulties associated in applying bare bone MVC to real world lies in In medium to large applications, centralized control and processing logic in the servlet – the greatest plus of MVC is also its weakness.  Consider a mediocre application with 15 JSPs. Assume that each page has five hyperlinks (or five form submissions). The total number of user requests to be handled in the application is 75. Since we are using MVC framework, a centralized controller servlet handles every user request. For each type of incoming request there is “if” block in the doGet method of the controller Servlet to process the request and dispatch to the next view. For this mediocre application of ours, the controller Servlet has 75 if blocks. Even if you assume that each if block delegates the request handling to helper classes it is still no good. You can only imagine how bad it gets for a complex enterprise web application. So, we have a problem at hand. The Controller Servlet that started out as the greatest thing next to sliced bread has gone bad. It has put on a lot of weight to become a Fat Controller.
  • 36. MVC with Configurable Controller
  • 37. Configurable Controller Servlet Code Example Servlet Code
  • 38. MVC with Configurable Controller How It works 1. Properties file :It contains information in key value pair which is actually one to one mapping URL for each http request and handler class. There is a unique handler class for each url. 2 . Controller Servlet loads the properties file on startup 3 . When the HTTP request arrives from the client, the Controller Servlet looks up in a properties file to decide on the right Handler class for the HTTP request.This Handler class is referred to as the Request Handler. 4 . The Request Handler contains the presentation logic for that HTTP request including business logic invocation. In other words, the Request Handler does everything that is needed to handle the HTTP request. 5 . The only difference so far from the bare bone MVC is that the controller servlet looks up in a properties file to instantiate the Handlerinstead of calling it directly.
  • 39. MVC with Configurable Controller 6. there must be some sort of commonality between the Request Handlers for the servlet to generically instantiate the Request Handler. The commonal- -ity is that all Request Handler classes implement a common interface. Let us call this common interface as Handler Interface. In its simplest form, the Handler Interface has one method say, execute(). 7 . The Controller Servlet instantiates the Request Handler in the doGet() method and invokes the execute() method on it using Java Reflection. The execute() method invokes appropriate business logic from the middle tier and then selects the next view to be presented to the user. 8 . The controller servlet forwards the request to the selected JSP view. All this happens in the doGet() method of the controller servlet. The doGet() method lifecycle never changes.What changes is the Request Handler’s execute() method. 9. You just saw how Struts works in a nutshell!!! Instead of using a properties file like we did in this example, Struts uses XML to store more useful information.
  • 40.
  • 42. Struts Framework Components 1. All the core components of Struts framework belong to Controller category. 2. Struts has no components in the Model category. 3. Struts has only auxiliary components in View category. A collection of custom tags making it easy to interact with the controller. The View category is neither the core of Struts framework nor is it necessary.However it is a helpful library for using Struts effectively in JSP based rendering.
  • 43. Struts Framework Components Controller Category The ActionServlet and the collaborating classes form the controller and is the core of the framework. The collaborating classes are : 1.RequestProcessor 2.ActionForm 3.Action 4.ActionMapping 5 .Action Forward. View Category It contains utility classes – variety of custom tags making it easy to interact with the controller. It is not mandatory to use these utility classes. You can replace it with classes of your own.
  • 44. Struts Framework Components Model Category Struts does not offer any components in the Model Category.Many component models (CORBA, EJB) are available to implement the business tier. NOTE: Some people argue that ActionForm is the model component. However ActionForm is really part of the controller. The Struts documentation also speaks along similar lines. It is just View Data Transfer Object – a regular JavaBeans that has dependencies on the Struts classes and used for transferring the data to various classes within the controller.
  • 45. Struts Request Lifecycle A request from the client browser creates an HTTP request which comes to the servlet container. Step 1 : Servlet container looks up into web.xml,using load-on-startup Instantiate the ActionServlet and do following three tasks: First Task : The ActionServlet takes the Struts Config file name as an init-param. At startup, in the init() method, the ActionServlet reads the Struts Config file and load into memory.
  • 46. Struts Request Lifecycle Second Task : If the user types http://localhost:8080/app/submitForm.do in the browser URL bar, the URL will be intercepted and processed by the ActionServlet since the URL has a pattern *.do, with a suffix of "do". Because servlet-mapping is <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> Third Task : Then ActionServlet delegates the request handling to another class called RequestProcessor by invoking its process() method.
  • 47. Struts Request Lifecycle Step 2 : The RequestProcessor does the following in its process() method a) The RequestProcessor looks up the configuration file for the URL pattern /submitForm (if the URL is http://localhost:8080/app/submitForm.do). and and finds the XML block (ActionMapping). ActionMapping from struts-config.xml
  • 48. Struts Request Lifecycle b) The RequestProcessor instantiates the EmpForm and puts it in appropriate scope – either session or request.The RequestProcessor determines the appropriate scope by looking at the scope attribute in the same ActionMapping. c) RequestProcessor iterates through the HTTP request parameters and populates the EmpForm. d) the RequestProcessor checks for the validateattribute in the ActionMapping. If the validate is set to true, the RequestProcessor invokes the validate() method on the EmpForm instance. This is the method where you can put all the html form data validations. If Validate fail the RequestProcessor looks for the input attribute and return to JSP page mentioned in input tag. If Validate pass goto next step. e) The RequestProcessor instantiates the Action class specified in the ActionMapping (EmpAction) and invokes the execute() method on the EmpAction instance.
  • 49. Struts Request Lifecycle Signature of the execute method : f)Association of the logical name and the physical JSP page is encapsulated in the ActionForward instance returned from the execute method. In return mapping.findForward("success") RequestProcessor looks for the success attribute and forward to JSP page mentioned in success tag. i.e success.jsp. In return mapping.findForward("failure") RequestProcessor looks for the failure attribute and forward to JSP page mentioned in failure tag. i.e. failure.jsp In J2EE terms, this is referred to as dispatching the view to the user.
  • 50. ‘Simple Hello World’ Example Requirements : Softwares 1. Eclipse IDE http://www.eclipse.org/downloads/ 2. Tomcat Server http://tomcat.apache.org/download-60.cgi 3. JDK www.oracle.com/technetwork/java/javase/downloads/index.html Libraries Struts 1.3 FILES XML Java 1.web.xml 1.HelloWorldAction.java 2.struts-config.xml 2.HelloWorldForm.java JSP 1.HelloWorld.jsp 2.index.jsp 3.failure.jsp http://struts.apache.org/download.cgi
  • 51. Dynamic Web Project – Directory Structure
  • 60. STEPS TO EXECUTE 1. Create dynamic web project in eclipse 2. Add jsp,xml and java files according to directory structure. 3. Add struts libraries in Web-INF/lib folder. 4. Add same struts libraries in java build path(Right click on main project ->properties->java build path->libraries ->add external jar 5. Add tomcat server (Windows menu -> show view ->servers ->OK 6. Go to server wizard -> add new server - >Apache -> select the tomcat version you downloaded ->Next ->Browse ->select the folder where you extracted or installed the downloaded tomcat ->finish 7. After adding server,right click on Project-> Run as -> Run on Server ->select server you added ->Finish
  • 61. First run – On Startup
  • 64. THANK YOU !!! F EEDBACK : WADEKARANUP @ GMAIL . COM