Monday, April 10, 2017

Document Web Routing


Direct Web Remoting (DWR) technology developed by Joe Walker and maintained by the small IT consultancy Getahead in UK.

DWR is a RPC library which makes it easy to call Java functions from JavaScript and to call JavaScript functions from Java (a.k.a Reverse Ajax).

DWR takes a novel approach to Ajax by dynamically generating JavaScript code based on Java classes.

DWR has a number of features like call batching, marshalling of virtually any data-structure between Java and Javascript (including binary file uploading and downloading), exception handling, advanced CSRF protection and deep integration with several Java server-side technologies like Spring and Guice.

DWR consists of two main parts:
  • A Java Servlet running on the server that processes requests and sends responses back to the browser.
  • JavaScript running in the browser that sends requests and can dynamically update the webpage.
DWR works by dynamically generating Javascript based on Java classes. The code does some Ajax magic to make it feel like the execution is happening on the browser, but in reality the server is executing the code and DWR is marshalling the data back and forwards.
This method of remoting functions from Java to JavaScript gives DWR users a feel much like conventional RPC mechanisms like RMI or SOAP, with the benefit that it runs over the web without requiring web-browser plug-ins.
The DWR project is developing a method of automatically creating Java versions of JavaScript APIs which developers can use to control browsers from the server. A server-side version of the TIBCO GI library is currently in alpha release, and the DWR project aims to expand this to cover other client side APIs including the Dojo Toolkit, JQuery, YUI, Ext and others.
DWR integration with Maven:-

Project Structure 
Before we start adding some code to our application lets take a look at overall project structure. Create a simple 'web application' project in 'Eclipse' and add all code files to it as mentioned in part of this blog.



pom.xml
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.project.in</groupId>
  5. <artifactId>DemoProject</artifactId>
  6. <version>DemoProject</version>
  7. <packaging>war</packaging>
  8. <dependencies>
  9. <dependency>
  10. <groupId>commons-logging</groupId>
  11. <artifactId>commons-logging</artifactId>
  12. <version>1.1.1</version>
  13. </dependency>
  14. <dependency>
  15. <groupId>commons-beanutils</groupId>
  16. <artifactId>commons-beanutils</artifactId>
  17. <version>1.8.3</version>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.directwebremoting</groupId>
  21. <artifactId>dwr</artifactId>
  22. <version>2.0.10</version>
  23. </dependency>
  24. </dependencies>
  25. </project>


/webapp/WEB-INF/web.xml
First of all add some entries to your 'web.xml' so that the 'tomcat container' could understand the behavior of application. Add a servlet entry point for 'DWRServlet' to make the container understand that all dwr configuration is done in it and going to be used accordingly. Now add 'url-mapping' to 'DWRServlet' , this tells the container that all requests with /'.html' extention are going to be handled by spring itself. At the end of the file a entry for welcome file is added that indicates the starting point of the application.


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. version="2.5">
  6. <display-name>DemoProject</display-name>
  7. <servlet>
  8. <servlet-name>dwr-invoker</servlet-name>
  9. <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
  10. <init-param>
  11. <param-name>debug</param-name>
  12. <param-value>true</param-value>
  13. </init-param>
  14. <init-param>
  15. <param-name>crossDomainSessionSecurity</param-name>
  16. <param-value>false</param-value>
  17. </init-param>
  18. </servlet>
  19. <servlet-mapping>
  20. <servlet-name>dwr-invoker</servlet-name>
  21. <url-pattern>/dwr/*</url-pattern>
  22. </servlet-mapping>
  23. <welcome-file-list>
  24. <welcome-file>index.jsp</welcome-file>
  25. </welcome-file-list>
  26. </web-app>


/webapp/WEB-INF/dwr.xml


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://directwebremoting.org/schema/dwr20.dtd">
  3. <dwr>
  4. <allow>
  5. <convert match="com.np.in.Employee" converter="bean"
  6. javascript="crmDwr">
  7. <param name="include" value="id,name"></param>
  8. </convert>
  9. <create creator="new" javascript="crmDwr">
  10. <param name="class" value="com.np.in.DwrManagerImpl" />
  11. </create>
  12. <convert converter="exception" match="java.lang.Exception" />
  13. <convert converter="bean" match="java.lang.StackTraceElement" />
  14. </allow>
  15. </dwr>




Monday, January 25, 2016

Spring Hibernate Integration Hello World Tutorial (Spring + Hibernate + MySql)

Today I will walk you through the integration of Hibernate with a Spring MVC application using annotations. In this particular blog, we will create a simple Hello World application in Spring and Hibernate. Our objective for today's discussion id to create a simple registration form using spring'stage, the data is to persist in a MySql database and after that, we will retrieve the data from the database and will show the data in table form.

Spring MVC and Hibernate Integration CRUD with Maven

Database
The very first step to start an application is creating a database, lets create a database with name 'beingjavaguys_db' and create a 'USER' table in it. To create database simply copy the script below and run it in your 'query editor'. This will create a database and table with required fields.
  1. DROP TABLE IF EXISTS `USER`;  
  2. /*!40101 SET @saved_cs_client     = @@character_set_client */;  
  3. /*!40101 SET character_set_client = utf8 */;  
  4. CREATE TABLE `USER` (  
  5.   `user_id` int(11) NOT NULL AUTO_INCREMENT,  
  6.   `first_name` varchar(45) DEFAULT NULL,  
  7.   `last_name` varchar(45) DEFAULT NULL,  
  8.   `gender` varchar(45) DEFAULT NULL,  
  9.   `city` varchar(45) DEFAULT NULL,  
  10.   PRIMARY KEY (`user_id`)  
  11. )   

Project Structure 
Before we start adding some code to our application lets take a look at overall project structure. Create a simple 'web application' project in 'Eclipse' and add all code files to it as mentioned in rest part of this blog.

/WebContent/WEB-INF/web.xml
First of all add some entries to your 'web.xml' so that the 'tomcat container' could understand the behavior of application. Add a servlet entry point for 'DispatcherServlet' to make the container understand that all spring configuration is done in it and going to be used accordingly. Now add 'url-mapping' to 'DispatcherServlet' , this tells the container that all requests with /'.html' extention are going to be handled by spring itself. At the end of the file a entry for welcome file is added that indicates the starting point of the application.
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
  5.   
  6.     <servlet>  
  7.         <servlet-name>dispatcher</servlet-name>  
  8.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  9.         <load-on-startup>1</load-on-startup>  
  10.     </servlet>  
  11.   
  12.     <servlet-mapping>  
  13.         <servlet-name>dispatcher</servlet-name>  
  14.         <url-pattern>*.html</url-pattern>  
  15.     </servlet-mapping>  
  16.   
  17.     <welcome-file-list>  
  18.         <welcome-file>index.jsp</welcome-file>  
  19.     </welcome-file-list>  
  20.   
  21. </web-app>  

/WebContent/index.jsp
In 'index.jsp' a 'SendRedirect' is added that redirects the control to '/register.html' so that spring could take the command from this point.
  1. <%@page import="com.sun.mail.iap.Response"%>  
  2. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  3.     pageEncoding="UTF-8"%>  
  4.     <%response.sendRedirect("register.html"); %>  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  

/src/com/beingjavaguys/controller/HomeController.java
We have added a controller with name 'Home Controller' and configured it using required mappings. '@Controller' tells that the class is going to be used as a controller for the application. '@RequestMapping' tells that the method will behave like an action for the mentioned 'url pattern'. Whenever a request pattern will match to the pattern specified in '@RequestMapping' the code written in related method will be executed. Here you can see that the every action is returning an object of 'ModelAndView' class. 'ModelAndView' class offers a number of things to the application, the very first parameter that is passed to it, represents the name of view(required jsp file) that is going to be rendered after completion of action's code. The second parameter indicated a String value key for the object that is placed as third parameter. Using these capabilities we can send an object to view associated with a key.
  1. package com.beingjavaguys.controller;  
  2. import java.util.ArrayList;  
  3. import java.util.HashMap;  
  4. import java.util.Map;  
  5. import org.springframework.beans.factory.annotation.Autowired;  
  6. import org.springframework.stereotype.Controller;  
  7. import org.springframework.validation.BindingResult;  
  8. import org.springframework.web.bind.annotation.ModelAttribute;  
  9. import org.springframework.web.bind.annotation.RequestMapping;  
  10. import org.springframework.web.servlet.ModelAndView;  
  11. import com.beingjavaguys.domain.User;  
  12. import com.beingjavaguys.service.UserService;  
  13.   
  14. @Controller  
  15. public class HomeController {  
  16.   
  17.    @Autowired  
  18.     private UserService userService;  
  19.   
  20.   
  21.    @RequestMapping("/register")  
  22.     public ModelAndView getRegisterForm(@ModelAttribute("user") User user,  
  23.             BindingResult result) {  
  24.   
  25.         ArrayList<String> gender = new ArrayList<String>();  
  26.         gender.add("Male");  
  27.         gender.add("Female");  
  28.   
  29.         ArrayList<String> city = new ArrayList<String>();  
  30.         city.add("Delhi");  
  31.         city.add("Kolkata");  
  32.         cit.add("Chennai");  
  33.         city.add("Bangalore");  
  34.   
  35.         Map<String, Object> model = new HashMap<String, Object>();  
  36.         model.put("gender", gender);  
  37.         model.put("city", city);  
  38.   
  39.         System.out.println("Register Form");  
  40.         return new ModelAndView("Register""model", model);  
  41.   
  42.     }  
  43.   
  44.   
  45.     @RequestMapping("/saveUser")  
  46.     public ModelAndView saveUserData(@ModelAttribute("user") User user,  
  47.             BindingResult result) {  
  48.   
  49.         userService.addUser(user);  
  50.         System.out.println("Save User Data");  
  51.         return new ModelAndView("redirect:/userList.html");  
  52.   
  53.     }  
  54.   
  55.   
  56.     @RequestMapping("/userList")  
  57.     public ModelAndView getUserList() {  
  58.   
  59.         Map<String, Object> model = new HashMap<String, Object>();  
  60.         model.put("user", userService.getUser());  
  61.         return new ModelAndView("UserDetails", model);  
  62.   
  63.     }  
  64.   
  65. }  

/src/com/beingjavaguys/dao/UserDao.java
DAO stand for data access object, it makes it easy to communicate the application with database. We are using an interface here this implements standard industrial practices. Required methods are declared here and being implemented in related implementation class associated with it.
  1. package com.beingjavaguys.dao;  
  2.   
  3. import java.util.List;  
  4. import com.beingjavaguys.domain.User;  
  5.   
  6.   
  7. public interface UserDao {  
  8. public void saveUser ( User user );  
  9. public List<User> getUser();  
  10.   
  11. }  

/src/com/beingjavaguys/dao/UserDaoImpl.java
This is implementation class for UserDao interface, all methods declared in UserDao interface are implemented here to achieve the goal. 'saveUser()' method takes an User's object as parameter and persists it in the database using 'sessionFactory' object. Similarly 'getUser()' method is returning a list of User's object using a Hibernate Criteria query.
  1. package com.beingjavaguys.dao;  
  2.   
  3. import java.util.List;  
  4. import org.hibernate.SessionFactory;  
  5. import org.springframework.beans.factory.annotation.Autowired;  
  6. import org.springframework.stereotype.Repository;  
  7. import com.beingjavaguys.domain.User;  
  8.   
  9.   
  10. @Repository("userDao")  
  11. public class UserDaoImpl implements UserDao {  
  12.   
  13.   
  14.     @Autowired  
  15.     private SessionFactory sessionfactory;  
  16.   
  17.   
  18.     @Override  
  19.     @Transactional  
  20.     public void saveUser(User user) {  
  21.         sessionfactory.getCurrentSession().saveOrUpdate(user);  
  22.     }  
  23.   
  24.   
  25.     @Override  
  26.     @Transactional  
  27.     public List<User> getUser() {  
  28.   
  29.         @SuppressWarnings("unchecked")  
  30.         List<User> userlist = sessionfactory.getCurrentSession()  
  31.                 .createCriteria(User.class).list();  
  32.         return userlist;  
  33.   
  34.     }  
  35.   
  36. }  

/src/com/beingjavaguys/domain/User.java
To represent User entity within the application and to persist User's objects we uses a User class with all required fields. This is nothing but a simple java bean with some Hibernate annotations. @Entity tells that the class is a domain class that maps to a table in the database. The name attribute of '@Table' specifies the table name in the database. @Id tells that the related column is going to represent the 'primary key' for the table and @GeneratedValue show auto increment nature for related column. The name attribute of '@Column' specifies the related column name for the field.
  1. package com.beingjavaguys.domain;  
  2.   
  3. import javax.persistence.Column;  
  4. import javax.persistence.Entity;  
  5. import javax.persistence.GeneratedValue;  
  6. import javax.persistence.Id;  
  7. import javax.persistence.Table;  
  8.   
  9.   
  10. @Entity  
  11. @Table(name = "USER")  
  12. public class User {  
  13.   
  14.   
  15.   
  16.     @Id  
  17.     @GeneratedValue  
  18.     @Column(name = "user_id")  
  19.     private int id;  
  20.   
  21.   
  22.   
  23.     @Column(name = "first_name")  
  24.     private String firstName;  
  25.   
  26.   
  27.     @Column(name = "last_name")  
  28.     private String lastName;  
  29.   
  30.   
  31.     @Column(name = "gender")  
  32.     private String gender;  
  33.   
  34.   
  35.   
  36.     @Column(name = "city")  
  37.     private String City;  
  38.   
  39.   
  40.     public int getId() {  
  41.         return id;  
  42.     }  
  43.   
  44.   
  45.     public void setId(int id) {  
  46.         this.id = id;  
  47.   
  48.     }  
  49.   
  50.   
  51.     public String getFirstName() {  
  52.         return firstName;  
  53.   
  54.     }  
  55.   
  56.   
  57.     public void setFirstName(String firstName) {  
  58.         this.firstName = firstName;  
  59.   
  60.     }  
  61.   
  62.   
  63.     public String getLastName() {  
  64.         return lastName;  
  65.   
  66.     }  
  67.   
  68.   
  69.     public void setLastName(String lastName) {  
  70.         this.lastName = lastName;  
  71.     }  
  72.   
  73.   
  74.     public String getGender() {  
  75.         return gender;  
  76.   
  77.     }  
  78.   
  79.   
  80.     public void setGender(String gender) {  
  81.         this.gender = gender;  
  82.   
  83.     }  
  84.   
  85.   
  86.     public String getCity() {  
  87.         return City;  
  88.     }  
  89.   
  90.   
  91.     public void setCity(String city) {  
  92.         City = city;  
  93.     }  
  94. }  

/src/com/beingjavaguys/service/UserService.java
Service layer is added here to implement two layer architecture for the application, it works some kind of interface in between the application and database transactions. Its always a good practice to have a service layer in your application so that the application data can be isolated to database code and reusability can be enhanced.
  1. package com.beingjavaguys.service;  
  2.   
  3. import java.util.List;  
  4. import com.beingjavaguys.domain.User;  
  5. public interface UserService {  
  6.     public void addUser(User user);  
  7.     public List<User> getUser();  
  8.   
  9. }  


/src/com/beingjavaguys/service/UserServiceImpl.java
This is implementation for UserService interface, service methods are called in application controlled to perform database stuff.
  1. package com.beingjavaguys.service;  
  2. import java.util.List;  
  3. import org.springframework.beans.factory.annotation.Autowired;  
  4. import org.springframework.stereotype.Service;  
  5. import org.springframework.transaction.annotation.Propagation;  
  6. import org.springframework.transaction.annotation.Transactional;  
  7. import com.beingjavaguys.dao.UserDao;  
  8. import com.beingjavaguys.domain.User;  
  9.   
  10.   
  11. @Service  
  12. @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)  
  13. public class UserServiceImpl implements UserService {  
  14.   
  15.   
  16.     @Autowired  
  17.     UserDao userDao;  
  18.     @Override  
  19.     public void addUser(User user) {  
  20.         userDao.saveUser(user);  
  21.   
  22.     }  
  23.   
  24.   
  25.     @Override  
  26.     public List<User> getUser() {  
  27.         return userDao.getUser();  
  28.   
  29.     }  
  30. }  

/src/jdbc.properties
A property class is added here to specify all required database properties in a separated file, show_sql=true make all database queries to show on console.
  1. database.driver=com.mysql.jdbc.Driver  
  2. database.url=jdbc:mysql://localhost:3306/beingjavaguys_db  
  3. database.user=root  
  4. database.password=root  
  5. hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
  6. hibernate.show_sql=true  
  7. hibernate.hbm2ddl.auto=create/update   



/WebContent/WEB-INF/dispatcher-servlet.xml
Dispatcher servlet is the root of an spring application, all spring configurations goes here is a single file. The 'jspViewResolver' bean specifies the view files path and its prefix and suffix attributes makes it easy to use simple view names in application rather that specifying full path.
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xsi:schemaLocation="  
  6. http://www.springframework.org/schema/beans  
  7. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  8. http://www.springframework.org/schema/context  
  9. http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  10. http://www.springframework.org/schema/tx  
  11. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  
  12.   
  13.     <context:property-placeholder location="classpath:jdbc.properties" />  
  14.     <context:component-scan base-package="com.beingjavaguys" />  
  15.     <tx:annotation-driven transaction-manager="hibernateTransactionManager" />  
  16.     <bean id="jspViewResolver"  
  17.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  18.         <property name="viewClass"  
  19.             value="org.springframework.web.servlet.view.JstlView" />  
  20.         <property name="prefix" value="/WEB-INF/view/" />  
  21.         <property name="suffix" value=".jsp" />  
  22.     </bean>  
  23.   
  24.     <bean id="dataSource"  
  25.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  26.         <property name="driverClassName" value="${database.driver}" />  
  27.         <property name="url" value="${database.url}" />  
  28.         <property name="username" value="${database.user}" />  
  29.         <property name="password" value="${database.password}" />  
  30.     </bean>  
  31.   
  32.     <bean id="sessionFactory"  
  33.         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
  34.         <property name="dataSource" ref="dataSource" />  
  35.         <property name="annotatedClasses">  
  36.             <list>  
  37.                 <value>com.beingjavaguys.domain.User</value>  
  38.             </list>  
  39.         </property>  
  40.         <property name="hibernateProperties">  
  41.             <props>  
  42.                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>  
  43.                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>  
  44.             </props>  
  45.         </property>  
  46.     </bean>  
  47.   
  48.   
  49.   
  50.     <bean id="hibernateTransactionManager"  
  51.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  52.         <property name="sessionFactory" ref="sessionFactory" />  
  53.     </bean>  
  54.   
  55. </beans>  


/WebContent/WEB-INF/view/Register.jsp
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>  
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  6. <html>  
  7. <head>  
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  9. <title>Being Java Guys | Registration Form</title>  
  10. </head>  
  11. <body>  
  12. <center>  
  13.   
  14. <div style="color: teal;font-size: 30px">Being Java Guys | Registration Form</div>  
  15.   
  16.   
  17.   
  18. <c:url var="userRegistration" value="saveUser.html"/>  
  19. <form:form id="registerForm" modelAttribute="user" method="post" action="${userRegistration}">  
  20. <table width="400px" height="150px">  
  21. <tr>  
  22. <td><form:label path="firstName">First Name</form:label></td>  
  23. <td><form:input  path="firstName"/></td>  
  24. </tr>  
  25. <tr>  
  26. <td><form:label path="lastName">Last Name</form:label></td>  
  27. <td><form:input  path="lastName"/></td>  
  28. </tr>  
  29. <tr>  
  30. <td><form:label path="gender">Gender</form:label></td>  
  31. <td><form:radiobuttons path="gender" items="${model.gender}"/></td>  
  32. </tr>  
  33. <tr>  
  34. <td><form:label path="city">City</form:label></td>  
  35. <td><form:select path="city" items="${model.city}"></form:select></td>  
  36. </tr>  
  37. <tr><td></td><td>  
  38. <input type="submit" value="Register" />  
  39. </td></tr>  
  40. </table>  
  41. </form:form>  
  42.   
  43.   
  44. <a href="userList.html" >Click Here to see User List</a>  
  45. </center>  
  46. </body>  
  47. </html>  


/WebContent/WEB-INF/view/UserDetails.jsp
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3.     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  5. <html>  
  6. <head>  
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  8. <title>Being Java Guys | User Details</title>  
  9. </head>  
  10. <body>  
  11. <center>  
  12.   
  13. <div style="color: teal;font-size: 30px">Being Java Guys | User Details</div>  
  14.   
  15.   
  16.   
  17. <c:if test="${!empty user}">  
  18. <table border="1" bgcolor="black" width="600px">  
  19. <tr style="background-color: teal;color: white;text-align: center;" height="40px">  
  20. <td>User Id</td>  
  21. <td>First Name</td>  
  22. <td>Last Name</td>  
  23. <td>Gender</td>  
  24. <td>City</td>  
  25. </tr>  
  26. <c:forEach items="${user}" var="user">  
  27. <tr style="background-color:white;color: black;text-align: center;" height="30px" >  
  28. <td><c:out value="${user.id}"/></td>  
  29. <td><c:out value="${user.firstName}"/></td>  
  30. <td><c:out value="${user.lastName}"/></td>  
  31. <td><c:out value="${user.gender}"/></td>  
  32. <td><c:out value="${user.city}"/></td>  
  33. </tr>  
  34. </c:forEach>  
  35. </table>  
  36. </c:if>  
  37.   
  38.   
  39. <a href="register.html" >Click Here to add new User</a>  
  40. </center>  
  41. </body>  
  42. </html>  


Here we are done with creating a simple hello world application using Spring and Hibernate. Just run your application on server, if everything went right you will see output something like these screens showing below.


In this blog we went through Spring, Hibernate Integration process and we get to know 'How to create a simple hello world applicaton is springa and hibernate using annotations'. In upcoming blogs we will dive into some others tutorials using spring and hibernate technologies.