<div dir="ltr" style="text-align: justify;" trbidi="on">In this example show how to write a simple web based application with CRUD operation using <b>Spring3 MVC Framework with Hibernate3 using Annotation handling two database tables</b>(<b>Category &; Publication)</b>, which can handle CRUD inside its controllers. To start with it, let us have working STS IDE in place and follow the following steps to develop a Dynamic Form based Web Application using <b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/" target="_blank">Spring Web Framework</a>:</b></p>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<p> <i><b>Step 1:</b></i> Create a Database DAVDB on MySql Database and also we create <i><b>Category </b></i>and <i><b>Publication </b></i>tables on this database.</p>
<p><b><i>Category </i>Table</b></p>
<pre class="highlight" name="code">CREATE TABLE `category` ( 
 `categoryId` int(11) NOT NULL AUTO_INCREMENT, 
 `categoryName` varchar(255) DEFAULT NULL, 
 PRIMARY KEY (`categoryId`) 
) 
</pre>
<p>
<b><i>Publication </i>Table</b></p>
<pre class="highlight" name="code">CREATE TABLE `publication` ( 
 `pubId` int(11) NOT NULL AUTO_INCREMENT, 
 `content` varchar(255) DEFAULT NULL, 
 `Title` varchar(255) DEFAULT NULL, 
 `categoryId` int(11) DEFAULT NULL, 
 PRIMARY KEY (`pubId`), 
 KEY `FK23254A0CAF274936` (`categoryId`), 
 CONSTRAINT `FK23254A0CAF274936` FOREIGN KEY (`categoryId`) REFERENCES `category` (`categoryId`) 
) 
</pre>
<p>
<b>Step 2: </b>Create a <i><b>database.properties</b></i> for database configuration information in the resources folder under <i><b>src </b></i>folder in the created project.</p>
<pre class="highlight" name="code">database.driver=com.mysql.jdbc.Driver 
 database.url=jdbc:mysql://localhost:3306/DAVDB 
 database.user=root 
 database.password=root 
 hibernate.dialect=org.hibernate.dialect.MySQLDialect 
 hibernate.show_sql=true 
 hibernate.hbm2ddl.auto=create 
</pre>
<p>
<i><b>Step 3:</b></i> Create a Dynamic Web Project with a name <b>elhumeante </b>and create packages <i><b>com.dineshonjava.controller</b></i>,<i> <b>com.dineshonjava.bean</b>, <b>com.dineshonjava.dao</b>, <b>com.dineshonjava.service</b>, <b>com.dineshonjava.model</b></i> under the <i><b>src </b></i>folder in the created project.</p>
<p><i><b>Step 4:</b></i> Add below mentioned <i><b>Spring 3.0 and Hibernate 3.0 related libraries and other libraries</b></i> into the folder <i><b>WebRoot/WEB-INF/lib</b></i>. <br />
<img src="https://dineshonjava.com/wp-content/uploads/2013/05/mvclibs.jpg" alt="Spring CRUD Example using One to One Mapping of Two Tables"/></p>
<p><i><b>Step 5:</b> </i>Create a Java class <i><b>CategoryController, Publication</b></i><i><b>Controller, CategoryBean, PublicationBean, CategoryDao, CategoryDaoImpl, PublicationDao, PublicationDaoImpl, CategoryService, CategoryServiceImpl, ;PublicationService, </b></i><i><b>PublicationServiceImpl </b></i>under the respective packages..</p>
<p> <i><b>Step 6:</b></i> Create Spring configuration files <b><i>web.xml</i></b> and <i><b>sdnext-servlet.xml</b></i> under the<b><i> WebRoot/WEB-INF/ </i></b>and <b><i>WebRoot/WEB-INF/config</i></b> folders.</p>
<p> <i><b>Step 7: </b></i>Create a sub-folder with a name views under the <b><i>WebRoot/WEB-INF</i></b> folder. Create a view file <i><b>addCategory.jsp</b></i> and <b><i>addPublication.jsp</i></b> under this sub-folder.</p>
<p> <b><i>Step 8:</i> </b>The final step is to create the content of all the source and configuration files name <i><b>sdnext-servlet.xml</b></i> under the sub-folder<i><b> /WebRoot/WEB-INF/config </b></i>and export the application as explained below.</p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/category.png"/></div>
<p></p>
<h2><i>Application Architecture</i></h2>
<p>We will have a layered architecture for our demo application. The database will be accessed by a <b>Data Access layer</b> popularly called as <b>DAO Layer(<i>CategoryDao</i>, <i>PublicationDao</i>)</b>. This layer will use Hibernate API to interact with database. The DAO layer will be invoked by a service layer. In our application we will have a <b>Service interface</b> called <b><i>CategoryService, PublicationService</i></b>.</p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/directory.png"/></div>
<p>
<i><b>CategoryBean.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.bean; 
 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Table; 
 
@Entity 
@Table(name="Category") 
public class CategoryBean { 
 
 @Id 
 @Column(name="categoryId") 
 @GeneratedValue(strategy=GenerationType.AUTO) 
 private Integer categoryId; 
 
 @Column(name="categoryName") 
 private String categoryName; 
 
 public Integer getCategoryId() { 
 return categoryId; 
 } 
 
 public void setCategoryId(Integer categoryId) { 
 this.categoryId = categoryId; 
 } 
 
 public String getCategoryName() { 
 return categoryName; 
 } 
 
 public void setCategoryName(String categoryName) { 
 this.categoryName = categoryName; 
 } 
} 
 
</pre>
<p><b><br />
<i>PublicationBean.java</i></b></p>
<pre class="highlight" name="code">package com.dineshonjava.bean; 
 
import java.io.Serializable; 
 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.OneToOne; 
import javax.persistence.Table; 
 
@Entity 
@Table(name="Publication") 
public class PublicationBean implements Serializable{ 
 
 private static final long serialVersionUID = 1L; 
 
 @Id 
 @GeneratedValue(strategy=GenerationType.AUTO) 
 @Column(name = "pubId") 
 private Integer pubId; 
 
 @Column(name="Title") 
 private String pubTitle; 
 
 @OneToOne 
 @JoinColumn(name="categoryId") 
 private CategoryBean category; 
 
 @Column(name="content") 
 private String pubContent; 
 
 public Integer getPubId() { 
 return pubId; 
 } 
 public void setPubId(Integer pubId) { 
 this.pubId = pubId; 
 } 
 public String getPubTitle() { 
 return pubTitle; 
 } 
 public void setPubTitle(String pubTitle) { 
 this.pubTitle = pubTitle; 
 } 
 public String getPubContent() { 
 return pubContent; 
 } 
 public CategoryBean getCategory() { 
 return category; 
 } 
 public void setCategory(CategoryBean category) { 
 this.category = category; 
 } 
 public void setPubContent(String pubContent) { 
 this.pubContent = pubContent; 
 } 
} 
 
</pre>
<p>
<i><b>CategoryDao.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.dao; 
 
import java.util.List; 
 
import com.dineshonjava.bean.CategoryBean; 
 
public interface CategoryDao { 
 
 public void addCategory(CategoryBean categoryBean); 
 
 public List<;CategoryBean>; getCategories(); 
 
 public CategoryBean getCategory(int categoryId); 
 
 public void deleteCategory(int categoryId); 
} 
</pre>
<p>
<i><b>PublicationDao.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.dao; 
 
import java.util.List; 
 
import com.dineshonjava.bean.PublicationBean; 
 
public interface PublicationDao { 
 
 public void addPublication(PublicationBean publicationBean); 
 
 public List<;PublicationBean>; getPublications(); 
 
 public PublicationBean getPublication(int pubId); 
 
 public void deletePublication(int pubId); 
} 
 
</pre>
<p>
<i><b>CategoryDaoImpl.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.dao; 
 
import java.util.List; 
 
import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Repository; 
 
import com.dineshonjava.bean.CategoryBean; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
 
@Repository("categoryDao") 
public class CategoryDaoImpl implements CategoryDao { 
 
 @Autowired 
 private SessionFactory sessionFactory; 
 
 @Override 
 public void addCategory(CategoryBean categoryBean) { 
 sessionFactory.getCurrentSession().saveOrUpdate(categoryBean); 
 } 
 
 @SuppressWarnings("unchecked") 
 @Override 
 public List<;CategoryBean>; getCategories() { 
 return (List<;CategoryBean>;) sessionFactory.getCurrentSession().createCriteria(CategoryBean.class).list(); 
 } 
 
 @Override 
 public CategoryBean getCategory(int categoryId) { 
 return (CategoryBean) sessionFactory.getCurrentSession().get(CategoryBean.class, categoryId); 
 } 
 
 @Override 
 public void deleteCategory(int categoryId) { 
 sessionFactory.getCurrentSession().createQuery("DELETE FROM category WHERE categoryId = "+categoryId).executeUpdate(); 
 } 
 
} 
 
</pre>
<p>
<i><b>PublicationDaoImpl.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.dao; 
 
import java.util.List; 
 
import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Repository; 
 
import com.dineshonjava.bean.PublicationBean; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
 
@Repository("publicationDao") 
public class PublicationDaoImpl implements PublicationDao { 
 
 @Autowired 
 private SessionFactory sessionFactory; 
 
 public void addPublication(PublicationBean publicationBean) { 
 sessionFactory.getCurrentSession().saveOrUpdate(publicationBean); 
 } 
 
 @SuppressWarnings("unchecked") 
 @Override 
 public List<;PublicationBean>; getPublications() { 
 return (List<;PublicationBean>;) sessionFactory.getCurrentSession().createCriteria(PublicationBean.class).list(); 
 } 
 
 @Override 
 public PublicationBean getPublication(int pubId) { 
 return (PublicationBean) sessionFactory.getCurrentSession().get(PublicationBean.class, pubId); 
 } 
 
 @Override 
 public void deletePublication(int pubId) { 
 sessionFactory.getCurrentSession().createQuery("DELETE FROM Publication WHERE pubId = "+pubId).executeUpdate(); 
 } 
 
} 
 
</pre>
<p>
<i><b>CategoryService.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.service; 
 
import java.util.List; 
 
import com.dineshonjava.bean.CategoryBean; 
 
public interface CategoryService { 
 
 public void addCategory(CategoryBean categoryBean); 
 
 public List<;CategoryBean>; getCategories(); 
 
 public CategoryBean getCategory(int categoryId); 
 
 public void deleteCategory(int categoryId); 
 
} 
 
</pre>
<p><i><b>CategoryServiceImpl.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.service; 
 
import java.util.List; 
 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service; 
import org.springframework.transaction.annotation.Propagation; 
import org.springframework.transaction.annotation.Transactional; 
 
import com.dineshonjava.bean.CategoryBean; 
import com.dineshonjava.dao.CategoryDao; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
 
@Service("categoryService") 
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true) 
public class CategoryServiceImpl implements CategoryService { 
 
 @Autowired 
 private CategoryDao categoryDao; 
 
 @Transactional(propagation = Propagation.REQUIRED, readOnly = false) 
 public void addCategory(CategoryBean categoryBean) { 
 categoryDao.addCategory(categoryBean); 
 } 
 
 @Override 
 public List<;CategoryBean>; getCategories() { 
 return categoryDao.getCategories(); 
 } 
 
 @Override 
 public CategoryBean getCategory(int categoryId) { 
 return categoryDao.getCategory(categoryId); 
 } 
 
 @Override 
 public void deleteCategory(int categoryId) { 
 categoryDao.deleteCategory(categoryId); 
 } 
 
} 
 
</pre>
<p><i><b>PublicationService.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.service; 
 
import java.util.List; 
 
import com.dineshonjava.bean.PublicationBean; 
 
public interface PublicationService { 
 
 public void addPublication(PublicationBean publicationBean); 
 
 public List<;PublicationBean>; getPublications(); 
 
 public PublicationBean getPublication(int pubId); 
 
 public void deletePublication(int pubId); 
} 
 
</pre>
<p><i><b>PublicationServiceImpl.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.service; 
 
import java.util.List; 
 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service; 
import org.springframework.transaction.annotation.Propagation; 
import org.springframework.transaction.annotation.Transactional; 
 
import com.dineshonjava.bean.PublicationBean; 
import com.dineshonjava.dao.PublicationDao; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Service("publicationService") 
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true) 
public class PublicationServiceImpl implements PublicationService { 
 
 @Autowired 
 private PublicationDao publicationDao; 
 
 @Transactional(propagation = Propagation.REQUIRED, readOnly = false) 
 public void addPublication(PublicationBean publicationBean) { 
 publicationDao.addPublication(publicationBean); 
 } 
 
 public List<;PublicationBean>; getPublications() { 
 return publicationDao.getPublications(); 
 } 
 
 @Override 
 public PublicationBean getPublication(int pubId) { 
 return publicationDao.getPublication(pubId); 
 } 
 
 @Override 
 public void deletePublication(int pubId) { 
 publicationDao.deletePublication(pubId); 
 } 
 
} 
 
</pre>
<p>
<i><b>CategoryController.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.controller; 
 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.validation.BindingResult; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 
 
import com.dineshonjava.bean.CategoryBean; 
import com.dineshonjava.service.CategoryService; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Controller 
public class CategoryController { 
 
 @Autowired 
 private CategoryService categoryService; 
 
 @RequestMapping(value = "/saveCategory", method = RequestMethod.POST) 
 public ModelAndView saveEmployee(@ModelAttribute("command") CategoryBean category, 
 BindingResult result) { 
 categoryService.addCategory(category); 
 return new ModelAndView("redirect:/addCategory.html"); 
 } 
 
 @RequestMapping(value = "/addCategory", method = RequestMethod.GET) 
 public ModelAndView addCategory(@ModelAttribute("command") CategoryBean category, 
 BindingResult result) { 
 Map<;String, Object>; model = new HashMap<;String, Object>;(); 
 model.put("categories", categoryService.getCategories()); 
 return new ModelAndView("addCategory", model); 
 } 
 
 @RequestMapping(value = "/deleteCategory", method = RequestMethod.GET) 
 public ModelAndView deleteCategory(@ModelAttribute("command") CategoryBean category, 
 BindingResult result) { 
 categoryService.deleteCategory(category.getCategoryId()); 
 Map<;String, Object>; model = new HashMap<;String, Object>;(); 
 model.put("categories", categoryService.getCategories()); 
 return new ModelAndView("addCategory", model); 
 } 
 
 @RequestMapping(value = "/editCategory", method = RequestMethod.GET) 
 public ModelAndView editCategory(@ModelAttribute("command") CategoryBean category, 
 BindingResult result) { 
 Map<;String, Object>; model = new HashMap<;String, Object>;(); 
 model.put("category", categoryService.getCategory(category.getCategoryId())); 
 model.put("categories", categoryService.getCategories()); 
 return new ModelAndView("addCategory", model); 
 } 
 
 @RequestMapping(value="/categories", method = RequestMethod.GET) 
 public List<;CategoryBean>; getCategories() { 
 return categoryService.getCategories(); 
 } 
} 
 
</pre>
<p><i><b>PublicationController.java</b></i></p>
<pre class="highlight" name="code">package com.dineshonjava.controller; 
 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.validation.BindingResult; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 
 
import com.dineshonjava.bean.PublicationBean; 
import com.dineshonjava.service.CategoryService; 
import com.dineshonjava.service.PublicationService; 
 
@Controller 
public class PublicationController { 
 
 @Autowired 
 private PublicationService publicationService; 
 
 @Autowired 
 private CategoryService categoryService; 
 
 @RequestMapping(value = "/savePublication", method = RequestMethod.POST) 
 public ModelAndView saveEmployee(@ModelAttribute("command") PublicationBean publication, 
 BindingResult result) { 
 publicationService.addPublication(publication); 
 return new ModelAndView("redirect:/addPublication.html"); 
 } 
 
 @RequestMapping(value = "/addPublication", method = RequestMethod.GET) 
 public ModelAndView addPublication(@ModelAttribute("command") PublicationBean publication, 
 BindingResult result) { 
 Map<;String, Object>; model = new HashMap<;String, Object>;(); 
 model.put("publications", publicationService.getPublications()); 
 model.put("categories", categoryService.getCategories()); 
 return new ModelAndView("addPublication", model); 
 } 
 
 @RequestMapping(value = "/deletePublication", method = RequestMethod.GET) 
 public ModelAndView deletePublication(@ModelAttribute("command") PublicationBean publication, 
 BindingResult result) { 
 publicationService.deletePublication(publication.getPubId()); 
 Map<;String, Object>; model = new HashMap<;String, Object>;(); 
 model.put("publications", publicationService.getPublications()); 
 model.put("categories", categoryService.getCategories()); 
 return new ModelAndView("addPublication", model); 
 } 
 
 @RequestMapping(value = "/editPublication", method = RequestMethod.GET) 
 public ModelAndView editPublication(@ModelAttribute("command") PublicationBean publication, 
 BindingResult result) { 
 Map<;String, Object>; model = new HashMap<;String, Object>;(); 
 model.put("publication", publicationService.getPublication(publication.getPubId())); 
 model.put("publications", publicationService.getPublications()); 
 model.put("categories", categoryService.getCategories()); 
 return new ModelAndView("addPublication", model); 
 } 
 
 @RequestMapping(value="/publications", method = RequestMethod.GET) 
 public List<;PublicationBean>; getPublications() { 
 return publicationService.getPublications(); 
 } 
} 
 
</pre>
<p>
<b>Spring Web configuration file <i>web.xml</i></b></p>
<pre class="highlight" name="code"><;?xml version="1.0" encoding="UTF-8"?>; 
<;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">; 
 
 <;servlet>; 
 <;servlet-name>;sdnext<;/servlet-name>; 
 <;servlet-class>;org.springframework.web.servlet.DispatcherServlet<;/servlet-class>; 
 <;init-param>; 
 <;param-name>;contextConfigLocation<;/param-name>; 
 <;param-value>;/WEB-INF/config/sdnext-servlet.xml<;/param-value>; 
 <;/init-param>; 
 <;load-on-startup>;1<;/load-on-startup>; 
 <;/servlet>; 
 
 <;servlet-mapping>; 
 <;servlet-name>;sdnext<;/servlet-name>; 
 <;url-pattern>;*.html<;/url-pattern>; 
 <;/servlet-mapping>; 
 
 <;welcome-file-list>; 
 <;welcome-file>; 
 addCategory.html 
 <;/welcome-file>; 
 <;/welcome-file-list>; 
<;/web-app>; 
 
</pre>
<p>
<b>Spring Web configuration file <i>sdnext-servlet.xml</i></b></p>
<pre class="highlight" name="code"><;?xml version="1.0" encoding="UTF-8"?>; 
<;beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:context="http://www.springframework.org/schema/context" 
 xmlns:tx="http://www.springframework.org/schema/tx" 
 xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">; 
 
 <;context:property-placeholder location="classpath:resources/database.properties" />; 
 <;context:component-scan base-package="com.dineshonjava" />; 
 
 <;tx:annotation-driven transaction-manager="hibernateTransactionManager"/>; 
 
 <;bean id="jspViewResolver" 
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">; 
 <;property name="viewClass" 
 value="org.springframework.web.servlet.view.JstlView" />; 
 <;property name="prefix" value="/WEB-INF/view/" />; 
 <;property name="suffix" value=".jsp" />; 
 <;/bean>; 
 
 <;bean id="dataSource" 
 class="org.springframework.jdbc.datasource.DriverManagerDataSource">; 
 <;property name="driverClassName" value="${database.driver}" />; 
 <;property name="url" value="${database.url}" />; 
 <;property name="username" value="${database.user}" />; 
 <;property name="password" value="${database.password}" />; 
 <;/bean>; 
 
 <;bean id="sessionFactory" 
 class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">; 
 <;property name="dataSource" ref="dataSource" />; 
 <;property name="annotatedClasses">; 
 <;list>; 
 <;value>;com.dineshonjava.bean.CategoryBean<;/value>; 
 <;value>;com.dineshonjava.bean.PublicationBean<;/value>; 
 <;/list>; 
 <;/property>; 
 <;property name="hibernateProperties">; 
 <;props>; 
 <;prop key="hibernate.dialect">;${hibernate.dialect}<;/prop>; 
 <;prop key="hibernate.show_sql">;${hibernate.show_sql}<;/prop>; 
 <;prop key="hibernate.hbm2ddl.auto">;${hibernate.hbm2ddl.auto}<;/prop>; 
 <;/props>; 
 <;/property>; 
 <;/bean>; 
 
 <;bean id="hibernateTransactionManager" 
 class="org.springframework.orm.hibernate3.HibernateTransactionManager">; 
 <;property name="sessionFactory" ref="sessionFactory" />; 
 <;/bean>; 
<;/beans>; 
</pre>
<p>
<i><b>addCategory.jsp</b></i></p>
<pre class="highlight" name="code"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
<;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>; 
<;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
 <;head>; 
 <;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; 
 <;title>;Spring MVC Form Handling<;/title>; 
 <;/head>; 
 <;body>;<;center>; 
 <;h2>;Create New Category<;/h2>; 
 <;form:form method="POST" action="/elhumeante/saveCategory.html">; 
 <;table>; 
 <;tr>; 
 <;td>;<;form:label path="categoryId">;Category ID:<;/form:label>;<;/td>; 
 <;td>;<;form:input path="categoryId" readonly="true"/>;<;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;<;form:label path="categoryName">;Category Name:<;/form:label>;<;/td>; 
 <;td>;<;form:input path="categoryName" value="${category.categoryName}"/>;<;/td>; 
 <;/tr>; 
 
 <;tr>; 
 <;tr>; 
 <;td>;&;nbsp;<;/td>; 
 <;td>;<;input type="submit" value="SAVE"/>;<;/td>; 
 <;/tr>; 
 <;/table>; 
 <;/form:form>; 
 <;br/>; 
 <;c:if test="${!empty categories}">; 
 <;table align="center" border="1">; 
 <;tr>; 
 <;th>;Category ID<;/th>; 
 <;th>;Category Name<;/th>; 
 <;th>;Options<;/th>; 
 <;/tr>; 
 
 <;c:forEach items="${categories}" var="category">; 
 <;tr>; 
 <;td>;<;c:out value="${category.categoryId}"/>;<;/td>; 
 <;td>;<;c:out value="${category.categoryName}"/>;<;/td>; 
 <;td align="center">;<;a href="editCategory.html?categoryId=${category.categoryId}">;Edit<;/a>; | <;a href="deleteCategory.html?categoryId=${category.categoryId}">;Delete<;/a>;<;/td>; 
 <;/tr>; 
 <;/c:forEach>; 
 <;/table>; 
<;/c:if>; 
<;h2>;<;a href="addPublication.html">;Adding Publication<;/a>;<;/h2>; 
<;/center>; 
 <;/body>; 
<;/html>; 
</pre>
<p>
<i><b>addPublication.jsp</b></i></p>
<pre class="highlight" name="code"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
<;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>; 
<;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
 <;head>; 
 <;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; 
 <;title>;Spring MVC Form Handling<;/title>; 
 <;/head>; 
 <;body>; 
 <;center>; 
 <;h2>;Create New Publication<;/h2>; 
 <;form:form method="POST" action="/elhumeante/savePublication.html">; 
 <;table>; 
 <;tr>; 
 <;td>;<;form:label path="pubId">;Publication ID:<;/form:label>;<;/td>; 
 <;td>;<;form:input path="pubId" value="${publication.pubId}" readonly="true"/>;<;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;<;form:label path="pubTitle">;Publication Title:<;/form:label>;<;/td>; 
 <;td>;<;form:input path="pubTitle" value="${publication.pubTitle}"/>;<;/td>; 
 <;/tr>; 
 
 <;tr>; 
 <;td>; 
 <;form:label path="category.categoryId">;Publication Type:<;/form:label>; 
 <;/td>; 
 <;td>; 
 <;form:select path="category.categoryId" cssStyle="width: 150px;">; 
 <;option value="-1">;Select a type<;/option>; 
 <;c:forEach items="${categories}" var="category">; 
 <;option value="${category.categoryId}">;${category.categoryName}<;/option>; 
 <;/c:forEach>; 
 <;/form:select>; 
 <;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;<;form:label path="pubContent">;Publication Content:<;/form:label>;<;/td>; 
 <;td>;<;form:textarea path="pubContent" value="${publication.pubContent}" cssStyle="width: 150px;"/>;<;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;&;nbsp;<;/td>; 
 <;td>;<;input type="submit" value="SAVE"/>;<;/td>; 
 <;/tr>; 
 <;/table>; 
 <;/form:form>; 
 <;br/>; 
 <;c:if test="${!empty publications}">; 
 <;table align="center" border="1">; 
 <;tr>; 
 <;th>;ID<;/th>; 
 <;th>;Title<;/th>; 
 <;th>;Type<;/th>; 
 <;th>;Content<;/th>; 
 <;th>;Options<;/th>; 
 <;/tr>; 
 
 <;c:forEach items="${publications}" var="publication">; 
 <;tr>; 
 <;td>;<;c:out value="${publication.pubId}"/>;<;/td>; 
 <;td>;<;c:out value="${publication.pubTitle}"/>;<;/td>; 
 <;td>;<;c:out value="${publication.category.categoryName}"/>;<;/td>; 
 <;td>;<;c:out value="${publication.pubContent}"/>;<;/td>; 
 <;td align="center">;<;a href="editPublication.html?pubId=${publication.pubId}">;Edit<;/a>; | <;a href="deletePublication.html?pubId=${publication.pubId}">;Delete<;/a>;<;/td>; 
 <;/tr>; 
 <;/c:forEach>; 
 <;/table>; 
<;/c:if>; 
<;h2>;<;a href="addCategory.html">;Adding Category<;/a>;<;/h2>; 
<;/center>; 
 <;/body>; 
<;/html>; 
</pre>
<p>
Once you are done with creating source and configuration files, export your application. Right click on your application and use<b> Export->; WAR</b> File option and save your <b><i>elhumeante.war</i></b> file in Tomcat&#8217;s webapps folder.</p>
<p> Now start your Tomcat server and make sure you are able to access other web pages from webapps folder using a standard browser. Now try a URL <i><b>http://localhost:8181/elhumeante/ </b></i>and you should see the following result if everything is fine with your Spring Web Application:</p>
<p><i><b>Create category: </b></i></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/addcategory.png"/></div>
<p>
<i><b>Create Publication: ;</b></i></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/addpublication.png" /></div>
<p></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/addcategory1.png" /></div>
<p><b>Download Source code</b><br />
<a href="https://sites.google.com/a/dineshonjava.com/dineshonjava/dineshonjava/elhumeante.zip?attredirects=0&;d=1" target="_blank"><b>elhumeante.zip</b></a></p>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Spring MVC Related Posts</b></span></p>
<ol style="text-align: left;"><span style="color: #274e13;"></p>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><span style="color: red;">Spring MVC Web Tutorial</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-interview-questions-and-answers/"><span style="color: red;">Spring MVC Interview Questions</span></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-mvc/"><span style="color: red;">MVC Design Pattern</span></a></b></li>
<li><b><a href="https://dineshonjava.com/what-is-dispatcherservlet-in-spring-and-its-uses/"><span style="color: red;">Spring MVC DispatcherServlet </span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC WebApplicationContext and Root Application Context</span></a></b></li>
<li><b><a href="https://dineshonjava.com/stereotype-annotations-in-spring/"><span style="color: red;">Spring MVC @Controller Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestmapping-annotation-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestMapping Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-annotation-in-spring-mvc-with-example/"><span style="color: red;">Spring MVC @RequestParam Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC ContextLoaderListener</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-vs-pathvariable-annotations-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestParam and @PathVariable annotations</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-30-mvc-hello-world-example/"><span style="color: red;">Spring MVC Hello World Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-exception-handling-example/"><span style="color: red;">Spring MVC Exception Handling Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-with-hibernate-crud-example/"><span style="color: red;">Spring MVC with Hibernate CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-tiles-plugin-with-example/"><span style="color: red;">Spring MVC Tiles Plugin with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-and-interceptor-with/"><span style="color: red;">Spring MVC Interceptor with example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/integration-spring-mvc3-and-mongodb/"><span style="color: red;">Spring MVC with MongoDB CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-internationalization/"><span style="color: red;">Spring MVC Internationalization &#038; Localization with Example</span></a></b></li>
<p></span></ol>
</div>
<p></p>
<div style="text-align: center;"><b><;<;</b><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/">Spring Web MVC Framework</a></b><b> |<a href="https://dineshonjava.com/spring-tutorial/">index</a>| </b><b><b><a href="https://dineshonjava.com/spring-crud-example-using-many-to-one/">Spring Many to One Example</a></b></b><b>>;>;</b></div>
<p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-tutorial/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/spring-crud-example-using-many-to-one/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '465'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…