SlideShare a Scribd company logo
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 ©
Ad

More Related Content

What's hot (20)

Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
Ignacio Coloma
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
Pratchaya Suputsopon
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016
John Napiorkowski
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Guo Albert
 
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
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
Parashuram N
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
tutorialsruby
 
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
Matt Raible
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
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
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
tutorialsruby
 
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...
Atlassian
 
Os Leonard
Os LeonardOs Leonard
Os Leonard
oscon2007
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
Wen-Tien Chang
 
4. jsp
4. jsp4. jsp
4. jsp
AnusAhmad
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
Jim Driscoll
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016
John Napiorkowski
 
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
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
Parashuram N
 
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
Matt Raible
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
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
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
tutorialsruby
 
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...
Atlassian
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
Wen-Tien Chang
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
Jim Driscoll
 

Viewers also liked (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
gustavoeliano
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
Joshua Eckblad
 
Web Application Architecture
Web Application ArchitectureWeb Application Architecture
Web Application Architecture
Philip
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
Didier Girard
 
Java scalability considerations yogesh deshpande
Java scalability considerations   yogesh deshpandeJava scalability considerations   yogesh deshpande
Java scalability considerations yogesh deshpande
IndicThreads
 
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
Abdelmonaim Remani
 
Pervasive Web Application Architecture
Pervasive Web Application ArchitecturePervasive Web Application Architecture
Pervasive Web Application Architecture
UC San Diego
 
Pervasive computing and its Security Issues
Pervasive computing and its Security IssuesPervasive computing and its Security Issues
Pervasive computing and its Security Issues
Phearin Sok
 
Web of Things Application Architecture
Web of Things Application ArchitectureWeb of Things Application Architecture
Web of Things Application Architecture
Dominique Guinard
 
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
Harish Ganesan
 
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
gustavoeliano
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
Joshua Eckblad
 
Web Application Architecture
Web Application ArchitectureWeb Application Architecture
Web Application Architecture
Philip
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
Didier Girard
 
Java scalability considerations yogesh deshpande
Java scalability considerations   yogesh deshpandeJava scalability considerations   yogesh deshpande
Java scalability considerations yogesh deshpande
IndicThreads
 
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
Abdelmonaim Remani
 
Pervasive Web Application Architecture
Pervasive Web Application ArchitecturePervasive Web Application Architecture
Pervasive Web Application Architecture
UC San Diego
 
Pervasive computing and its Security Issues
Pervasive computing and its Security IssuesPervasive computing and its Security Issues
Pervasive computing and its Security Issues
Phearin Sok
 
Web of Things Application Architecture
Web of Things Application ArchitectureWeb of Things Application Architecture
Web of Things Application Architecture
Dominique Guinard
 
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
Harish Ganesan
 
Ad

Similar to Trustparency web doc spring 2.5 & hibernate (20)

Spring 3.0
Spring 3.0Spring 3.0
Spring 3.0
Ved Prakash Gupta
 
Servlets
ServletsServlets
Servlets
Abdalla Mahmoud
 
Rupicon 2014 Action pack
Rupicon 2014 Action packRupicon 2014 Action pack
Rupicon 2014 Action pack
rupicon
 
Java EE Services
Java EE ServicesJava EE Services
Java EE Services
Abdalla Mahmoud
 
Learn Drupal 8 Render Pipeline
Learn Drupal 8 Render PipelineLearn Drupal 8 Render Pipeline
Learn Drupal 8 Render Pipeline
Zyxware Technologies
 
Jsf
JsfJsf
Jsf
Anis Bouhachem Djer
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
RAJNISH KATHAROTIYA
 
Struts tutorial
Struts tutorialStruts tutorial
Struts tutorial
OPENLANE
 
Spring tutorial
Spring tutorialSpring tutorial
Spring tutorial
Sanjoy Kumer Deb
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
Brajesh Yadav
 
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
Juliana Lucena
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
[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
Huu Dat Nguyen
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
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...
varunsunny21
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Emprovise
 
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
than sare
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
Massimiliano Dessì
 
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
Arun Gupta
 
Rupicon 2014 Action pack
Rupicon 2014 Action packRupicon 2014 Action pack
Rupicon 2014 Action pack
rupicon
 
Struts tutorial
Struts tutorialStruts tutorial
Struts tutorial
OPENLANE
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
Brajesh Yadav
 
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
Juliana Lucena
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
[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
Huu Dat Nguyen
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
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...
varunsunny21
 
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
than sare
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 
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
Arun Gupta
 
Ad

Recently uploaded (20)

Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 

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 ©