SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
trustparency




               Spring 2.5 & Hibernate
This guide explains in detail an example of Spring 2.5 and Hibernate.
                                                                       You can download the code of the example at:


                                                      https://www.dropbox.com/s/23hna4kjc2zpf8y/spring2.5.rar?n=1151701

                    https://www.wetransfer.com/downloads/69e508b6731646d19eb8ee8094fb8fbd20130407090225/836b3b316555169f387db7e7df6b916b20130407090225/d0b40d




                 Título                                    Fecha                                        Autor                                   Versión

Web doc for Spring & Hibernate                        11/07/2012                        José Luis Muñoz de Morales                                 1.0




                                                                                                                                                           2


                                                              Copyright ©
INDEX


    1. Spring MVC............................................................................. 4

    2. Web Flow Case: Login............................................................ 5

    3. Web Flow Case: User Registration ...................................... 11
1. Spring MVC




In the following image is displayed the Spring architecture used in

trustparency web design.


Each entity represented below such as Handler Mapping, Dispacher

Servlet, Controller…etc    is a standard entity which belongs to Spring

framework.




                                                                      4


                             Copyright ©
2. Web Flow Case: First entry




          Petition: login.htm (it could be anyone)



      1. Login.htm is requested.


      2. URL is end with “.htm” extension, so it will redirect to
          “DispatcherServlet”         and          send     request    to    the     default
          “BeanNameUrlHandlerMapping”                 (in    our   case     its    name       is
          SimpleURLHandlerMapping).


          Explanation: the HandlerMapping is called                SimpleUrlHandlerMapping,   it
          receives the request, which is mapped within the proyecto-
          servlet.xml.




  Proyecto-servlet.xml (Spring)



<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
       <property name="defaultHandler" value="simpleUrlController"/>
                <property name="alwaysUseFullPath"><value>true</value></property>
       <property name="mappings">
           <props>
                <prop key="/login.htm">loginController</prop>
                <prop key="/dentro.htm">loginController</prop>
                <prop key="/userInicio.htm">loginController</prop>
                <prop key="/anadirUsuario.htm">anadirUsuarioController</prop>
           </props>
       </property>
    </bean>



                                                                                               5


                                     Copyright ©
3. BeanNameUrlHandlerMapping                    return    a    Controller         to   the
         DispatcherServlet. In our case the controller is called loginController
         as it could be shown in the text above (in yellow).




 DispatcherServlet forward a request to the Controller, LoginController. To
 recognize the controller.




     Proyecto-servlet.xml (Spring)

<bean id="loginController" class="proyecto.controllers.LoginController" >
     <property name="methodNameResolver">
        <bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
                        <property name="mappings">
                                <props>
                                           <prop key="/login.htm">login</prop>
                                           <prop key="/dentro.htm">dentro</prop>
                                           <prop key="/userInicio.htm">inicio</prop>

                                </props>
                        </property>




                                                                                              6


                                      Copyright ©
4. LoginController process it and return a ModelAndView object
               named “login”.



<bean id="loginController" class="proyecto.controllers.LoginController" >
      <property name="methodNameResolver">
                  <bean

          class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
                            <property name="mappings">
                                    <props>
                                               <prop key="/login.htm">login</prop>
                                               <prop key="/dentro.htm">dentro</prop>
                                               <prop key="/userInicio.htm">inicio</prop>

                                    </props>
                            </property>
                  </bean>
                  </property>
</bean>




<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          <property name="defaultHandler" value="simpleUrlController"/>
                  <property name="alwaysUseFullPath"><value>true</value></property>
          <property name="mappings">
             <props>
                  <prop key="/login.htm">loginController</prop>
                  <prop key="/dentro.htm">loginController</prop>
                  <prop key="/userInicio.htm">loginController</prop>
                  <prop key="/anadirUsuario.htm">anadirUsuarioController</prop>
             </props>
          </property>
     </bean>




                                                                                                  7


                                               Copyright ©
Proyecto.controllers.LoginController.java




   5. DispatcherServlet received the ModelAndView and call the
      viewResolver to process it.




      In our case, the viewResolver uses another technology to solve the
      name. These technology is called Tiles.
      According to the xml file TilesConfigurer is the class in charge of
      solving “the name”.


      We need to see the name “login” (returned by the Controller) into
      the proyecto-defs.xml.




                                                                        8


                               Copyright ©
Tiles send to the viewResolver the jsp, and this JSP file is sent to
the DispatcherServlet.


Finally, DispatcherServlet return the “Login.jsp” back to user.




JSP (Java Server Page): is a technology which combines html
language with java language to create dynamic pages. Java
language is included using the following tag.


      <% java code %>




                                                                   9


                         Copyright ©
Login.jsp: merge java code and hmtl, to create a complete html
respond to the user, which is what the user finally sees on the
his/her browser.




                                                             10


                    Copyright ©
3. Web Flow Case: User Registration




1. anadirUsuario.htm is requested, using submit method from client
   browser to send the data (post method).



2. URL is end with “.htm” extension, so it will redirect to
   “DispatcherServlet”         and       send     request   to    the     default
   “BeanNameUrlHandlerMapping”              (in    our   case    its    name   is
   SimpleURLHandlerMapping).


   Explanation:          the         HandlerMapping              is       called
   SimpleURLHandlerMapping. It receives the request, which is
   mapped within the proyecto-servlet.xml.




   Proyecto-servlet.xml (Spring)




                                                                               11


                           Copyright ©
3. BeanNameUrlHandlerMapping                             return         a       Controller                to      the
                     DispatcherServlet.           In     our       case           the         controller             is        called
                     anadirUsuarioController.


                4. DispatcherServlet forward request “/anadirUsuario.htm” to the
                     anadirUsuarioController, in our case.


           Proyecto-servlet.xml (Spring)




           Diagram: relation between objects:



AnadirUsuarioController.java                  UserCommand available at             UserCommand.java

(java class)                                  AnadirUsuarioController,             (POJOs java class)
                                              submit method.
It is the Controller in charge of                                                  * It contains the fields/attributes

the        dialog        with        the                                           mapped           in    the    data      base,       also

DispacherServlet.                                                                  available in the Web Form sent by the
                                                                                   user´s browser.




                                                                         The    JPS     is     called
                                                                         automatically by Spring.




UserValidator.java                                                                NuevoUsuario.jsp
(java class)                                                                      (form view JSP page)
Validates NuevoUsuario.jsp data, which are                                        <form              action="anadirUsuario.htm"
encapsulated into UserCommand.java.                                               method="post">
UserValidator   is   a   Spring   Framework                                       JSP        page    which      is   the       form   that
standard class, and it uses the method                                            contains          the    textfield       to    collect
“validate()”.                                                                     user´s data.



                                                                                                                                      12


                                                    Copyright ©
Relation between objets,
          all of them are related using /anadirusuario.htm request


Login.jsp: is the first object called, it is used as a door to see the form.


Proyecto-servlet.xml: it has a mapping of the request, indicating the
suitable Controller object to handle /anadirusuario.htm.


Be careful:


   1. this request not must be mapped within a Controller with a method,
       it must be have a unique entry, specifiying: Controller name,
       Command name, Command class, Validator and formView.


   2. The formView name (which is also a JSP file) must be included
       within proyecto-defs.xml, relating the jsp file used to collect user´s
       data.


nuevoUsuario.jsp: is the form view, which has the textfields where are
located the user´s data. These data is also encapsulated into the
command object calle userCommand.




                                                                               13


                               Copyright ©
 Analizing the same from the Controller perspective, known as
anadirUsuarioController


   Proyecto-servlet.xml (Spring)




Analysis of AnadirUsuarioController, has:


   -   userCommand: on submit, anadirUsuarioController receives a
       Command object, which is a container of the data sent from the
       browser.


                          anadirUsuarioController.java




       UserCommand.java



                                                         nuevoUsuario.jsp




                                                                            14


                               Copyright ©
Analysis of AnadirUsuarioController, has:


Property “userService”: is an attribute declared in the class file. In itself,
UserService is an interface (I guess that an instance is passed from
Spring´s Container, or better explained, an instance is injected by the
Container).


                                                           This layer has been
                                                           removed.




                                                                             15


                              Copyright ©
The final class in charge of implementing the userService methods is
userServiceImpl, which has the implemented method “insertar()”.




Proyecto-service.xml: relation between userService and DAO (userDAO)




UserDAO: is the class property within UserServiceImpl class, and it is
referred as bean, which is located in the file proyecto-data.xml.




Proyecto-data.xml




                                                                    16


                              Copyright ©
The bean “hibernateTemplate” is injected into usersDAO across Spring.
The bean is found at hibernate configuration file (xml), which is a class of
Spring´s Framework.


Proyecto-ConfigHibernate.xml




To solve “sessionFactory”, within the same file we found:




At this stage, the insert operation is done, and therefore data are save into
the data base using Hibernate framework.




                                                                           17


                             Copyright ©
5. AnadirUsuarioController, once the user object has been save at the
   end of the submit method, it returns a ModelAndView object named
   “detalleusuario” to the DispacherServlet.


   Proyecto.controllers.AnadirUsuarioController.java




   At the same time, is set into the request map (a map table to save
   data using Key-Value pairs) the object user with the identifier
   “usuario”, which could be used in the JSP file thereafter.


6. DispatcherServlet received the ModelAndView and call the
   viewResolver to process it.




   In our case, the viewResolver uses another technology to solve the
   name. These technology is called Tiles.



                                                                   18


                          Copyright ©
According to the xml file TilesConfigurer is the class in charge of
solve the name.


We need to see the name “detalleusuario” (returned by the
Controller) into the proyecto-defs.xml.




Tiles send to the viewResolver the jsp, and this JSP file is sent to
the DispatcherServlet.


Finally, DispatcherServlet return the “detalleUsuario.jsp” back to
user.




* Within detalleUsuario.jsp, is used the object usuario get from the
request using the identifier or key “usuario”¸which has been saved
by the Controller in the submit method.




                                                                  19


                         Copyright ©

Contenu connexe

Tendances

Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
Guy Nir
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
Spike Brehm
 
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
Atlassian
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
tutorialsruby
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
Wen-Tien Chang
 

Tendances (20)

Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
 
Os Leonard
Os LeonardOs Leonard
Os Leonard
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
 
4. jsp
4. jsp4. jsp
4. jsp
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 

En vedette

Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
Didier Girard
 
Pervasive Web Application Architecture
Pervasive Web Application ArchitecturePervasive Web Application Architecture
Pervasive Web Application Architecture
UC San Diego
 

En vedette (10)

Restructuring a Web Application, Using Spring and Hibernate
Restructuring a Web Application, Using Spring and HibernateRestructuring a Web Application, Using Spring and Hibernate
Restructuring a Web Application, Using Spring and Hibernate
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Web Application Architecture
Web Application ArchitectureWeb Application Architecture
Web Application Architecture
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
 
Java scalability considerations yogesh deshpande
Java scalability considerations   yogesh deshpandeJava scalability considerations   yogesh deshpande
Java scalability considerations yogesh deshpande
 
Introduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcIntroduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring Mvc
 
Pervasive Web Application Architecture
Pervasive Web Application ArchitecturePervasive Web Application Architecture
Pervasive Web Application Architecture
 
Pervasive computing and its Security Issues
Pervasive computing and its Security IssuesPervasive computing and its Security Issues
Pervasive computing and its Security Issues
 
Web of Things Application Architecture
Web of Things Application ArchitectureWeb of Things Application Architecture
Web of Things Application Architecture
 
Architecting an Highly Available and Scalable WordPress Site in AWS
Architecting an Highly Available and Scalable WordPress Site in AWS Architecting an Highly Available and Scalable WordPress Site in AWS
Architecting an Highly Available and Scalable WordPress Site in AWS
 

Similaire à Trustparency web doc spring 2.5 & hibernate

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 

Similaire à Trustparency web doc spring 2.5 & hibernate (20)

Spring 3.0
Spring 3.0Spring 3.0
Spring 3.0
 
Servlets
ServletsServlets
Servlets
 
Rupicon 2014 Action pack
Rupicon 2014 Action packRupicon 2014 Action pack
Rupicon 2014 Action pack
 
Java EE Services
Java EE ServicesJava EE Services
Java EE Services
 
Learn Drupal 8 Render Pipeline
Learn Drupal 8 Render PipelineLearn Drupal 8 Render Pipeline
Learn Drupal 8 Render Pipeline
 
Jsf
JsfJsf
Jsf
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
Struts tutorial
Struts tutorialStruts tutorial
Struts tutorial
 
Spring tutorial
Spring tutorialSpring tutorial
Spring tutorial
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
[Laptrinh.vn] lap trinh Spring Framework 3
[Laptrinh.vn] lap trinh Spring Framework 3[Laptrinh.vn] lap trinh Spring Framework 3
[Laptrinh.vn] lap trinh Spring Framework 3
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Trustparency web doc spring 2.5 & hibernate

  • 1. trustparency Spring 2.5 & Hibernate
  • 2. This guide explains in detail an example of Spring 2.5 and Hibernate. You can download the code of the example at: https://www.dropbox.com/s/23hna4kjc2zpf8y/spring2.5.rar?n=1151701 https://www.wetransfer.com/downloads/69e508b6731646d19eb8ee8094fb8fbd20130407090225/836b3b316555169f387db7e7df6b916b20130407090225/d0b40d Título Fecha Autor Versión Web doc for Spring & Hibernate 11/07/2012 José Luis Muñoz de Morales 1.0 2 Copyright ©
  • 3. INDEX 1. Spring MVC............................................................................. 4 2. Web Flow Case: Login............................................................ 5 3. Web Flow Case: User Registration ...................................... 11
  • 4. 1. Spring MVC In the following image is displayed the Spring architecture used in trustparency web design. Each entity represented below such as Handler Mapping, Dispacher Servlet, Controller…etc is a standard entity which belongs to Spring framework. 4 Copyright ©
  • 5. 2. Web Flow Case: First entry Petition: login.htm (it could be anyone) 1. Login.htm is requested. 2. URL is end with “.htm” extension, so it will redirect to “DispatcherServlet” and send request to the default “BeanNameUrlHandlerMapping” (in our case its name is SimpleURLHandlerMapping). Explanation: the HandlerMapping is called SimpleUrlHandlerMapping, it receives the request, which is mapped within the proyecto- servlet.xml. Proyecto-servlet.xml (Spring) <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="defaultHandler" value="simpleUrlController"/> <property name="alwaysUseFullPath"><value>true</value></property> <property name="mappings"> <props> <prop key="/login.htm">loginController</prop> <prop key="/dentro.htm">loginController</prop> <prop key="/userInicio.htm">loginController</prop> <prop key="/anadirUsuario.htm">anadirUsuarioController</prop> </props> </property> </bean> 5 Copyright ©
  • 6. 3. BeanNameUrlHandlerMapping return a Controller to the DispatcherServlet. In our case the controller is called loginController as it could be shown in the text above (in yellow). DispatcherServlet forward a request to the Controller, LoginController. To recognize the controller. Proyecto-servlet.xml (Spring) <bean id="loginController" class="proyecto.controllers.LoginController" > <property name="methodNameResolver"> <bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/login.htm">login</prop> <prop key="/dentro.htm">dentro</prop> <prop key="/userInicio.htm">inicio</prop> </props> </property> 6 Copyright ©
  • 7. 4. LoginController process it and return a ModelAndView object named “login”. <bean id="loginController" class="proyecto.controllers.LoginController" > <property name="methodNameResolver"> <bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/login.htm">login</prop> <prop key="/dentro.htm">dentro</prop> <prop key="/userInicio.htm">inicio</prop> </props> </property> </bean> </property> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="defaultHandler" value="simpleUrlController"/> <property name="alwaysUseFullPath"><value>true</value></property> <property name="mappings"> <props> <prop key="/login.htm">loginController</prop> <prop key="/dentro.htm">loginController</prop> <prop key="/userInicio.htm">loginController</prop> <prop key="/anadirUsuario.htm">anadirUsuarioController</prop> </props> </property> </bean> 7 Copyright ©
  • 8. Proyecto.controllers.LoginController.java 5. DispatcherServlet received the ModelAndView and call the viewResolver to process it. In our case, the viewResolver uses another technology to solve the name. These technology is called Tiles. According to the xml file TilesConfigurer is the class in charge of solving “the name”. We need to see the name “login” (returned by the Controller) into the proyecto-defs.xml. 8 Copyright ©
  • 9. Tiles send to the viewResolver the jsp, and this JSP file is sent to the DispatcherServlet. Finally, DispatcherServlet return the “Login.jsp” back to user. JSP (Java Server Page): is a technology which combines html language with java language to create dynamic pages. Java language is included using the following tag. <% java code %> 9 Copyright ©
  • 10. Login.jsp: merge java code and hmtl, to create a complete html respond to the user, which is what the user finally sees on the his/her browser. 10 Copyright ©
  • 11. 3. Web Flow Case: User Registration 1. anadirUsuario.htm is requested, using submit method from client browser to send the data (post method). 2. URL is end with “.htm” extension, so it will redirect to “DispatcherServlet” and send request to the default “BeanNameUrlHandlerMapping” (in our case its name is SimpleURLHandlerMapping). Explanation: the HandlerMapping is called SimpleURLHandlerMapping. It receives the request, which is mapped within the proyecto-servlet.xml. Proyecto-servlet.xml (Spring) 11 Copyright ©
  • 12. 3. BeanNameUrlHandlerMapping return a Controller to the DispatcherServlet. In our case the controller is called anadirUsuarioController. 4. DispatcherServlet forward request “/anadirUsuario.htm” to the anadirUsuarioController, in our case. Proyecto-servlet.xml (Spring) Diagram: relation between objects: AnadirUsuarioController.java UserCommand available at UserCommand.java (java class) AnadirUsuarioController, (POJOs java class) submit method. It is the Controller in charge of * It contains the fields/attributes the dialog with the mapped in the data base, also DispacherServlet. available in the Web Form sent by the user´s browser. The JPS is called automatically by Spring. UserValidator.java NuevoUsuario.jsp (java class) (form view JSP page) Validates NuevoUsuario.jsp data, which are <form action="anadirUsuario.htm" encapsulated into UserCommand.java. method="post"> UserValidator is a Spring Framework JSP page which is the form that standard class, and it uses the method contains the textfield to collect “validate()”. user´s data. 12 Copyright ©
  • 13. Relation between objets, all of them are related using /anadirusuario.htm request Login.jsp: is the first object called, it is used as a door to see the form. Proyecto-servlet.xml: it has a mapping of the request, indicating the suitable Controller object to handle /anadirusuario.htm. Be careful: 1. this request not must be mapped within a Controller with a method, it must be have a unique entry, specifiying: Controller name, Command name, Command class, Validator and formView. 2. The formView name (which is also a JSP file) must be included within proyecto-defs.xml, relating the jsp file used to collect user´s data. nuevoUsuario.jsp: is the form view, which has the textfields where are located the user´s data. These data is also encapsulated into the command object calle userCommand. 13 Copyright ©
  • 14.  Analizing the same from the Controller perspective, known as anadirUsuarioController Proyecto-servlet.xml (Spring) Analysis of AnadirUsuarioController, has: - userCommand: on submit, anadirUsuarioController receives a Command object, which is a container of the data sent from the browser. anadirUsuarioController.java UserCommand.java nuevoUsuario.jsp 14 Copyright ©
  • 15. Analysis of AnadirUsuarioController, has: Property “userService”: is an attribute declared in the class file. In itself, UserService is an interface (I guess that an instance is passed from Spring´s Container, or better explained, an instance is injected by the Container). This layer has been removed. 15 Copyright ©
  • 16. The final class in charge of implementing the userService methods is userServiceImpl, which has the implemented method “insertar()”. Proyecto-service.xml: relation between userService and DAO (userDAO) UserDAO: is the class property within UserServiceImpl class, and it is referred as bean, which is located in the file proyecto-data.xml. Proyecto-data.xml 16 Copyright ©
  • 17. The bean “hibernateTemplate” is injected into usersDAO across Spring. The bean is found at hibernate configuration file (xml), which is a class of Spring´s Framework. Proyecto-ConfigHibernate.xml To solve “sessionFactory”, within the same file we found: At this stage, the insert operation is done, and therefore data are save into the data base using Hibernate framework. 17 Copyright ©
  • 18. 5. AnadirUsuarioController, once the user object has been save at the end of the submit method, it returns a ModelAndView object named “detalleusuario” to the DispacherServlet. Proyecto.controllers.AnadirUsuarioController.java At the same time, is set into the request map (a map table to save data using Key-Value pairs) the object user with the identifier “usuario”, which could be used in the JSP file thereafter. 6. DispatcherServlet received the ModelAndView and call the viewResolver to process it. In our case, the viewResolver uses another technology to solve the name. These technology is called Tiles. 18 Copyright ©
  • 19. According to the xml file TilesConfigurer is the class in charge of solve the name. We need to see the name “detalleusuario” (returned by the Controller) into the proyecto-defs.xml. Tiles send to the viewResolver the jsp, and this JSP file is sent to the DispatcherServlet. Finally, DispatcherServlet return the “detalleUsuario.jsp” back to user. * Within detalleUsuario.jsp, is used the object usuario get from the request using the identifier or key “usuario”¸which has been saved by the Controller in the submit method. 19 Copyright ©