title: Spring MVC Hibernate web application
body: <p>Spring MVC + Hibernate web application with mysql database. 
  3 tables (products, members and cart to connect this two). Members table have two different users: admin and customer.
  It should be something like Online Store.
  To have Administrator and Customer users. Admin entering new, edit and delete products. Customer to list all products and add to cart part.
  But before that it should have log in and sign up part. So Admin or Customer can log in or sign up. 
  So I have welcome page, index.jsp, from which I need links to:</p>
  
  <p>all_products.jsp -> list all products from products table mysql database</p>
  
  <p>signup.jsp -> Add new member form and sending data to members table mysql database.</p>
  
  <p>login.jsp -> Log In form</p>
  
  <p>From login.jsp depending who logged in:</p>
  
  <p>Customer -> index.jsp</p>
  
  <p>Admin -> admin.jsp</p>
  
  <p>admin.jsp -> add.jsp, all_products.jsp with edit and delete option.</p>
  
  <p>add.jsp-> add new product form</p>
  
  <p>I setup up a new project in Netbeans, with Spring mvc and hibernate framework, connect with mysql database, set up server, glassfish... etc...</p>
  
  <p>Then add...</p>
  
  <p>Members.java</p>
  
  <pre><code>package model;
  
  import java.util.HashSet;
  import java.util.Set;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity(name="members")
  public class Members  implements java.io.Serializable {
  
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO) 
   private int memberId;
   private String userName;
   private String password;
   private String fullName;
   private String email;
   private String address;
   private String gender;
   private String dateOfBirth;
   private String memberType;
   private Set&lt;Cart&gt; carts = new HashSet&lt;Cart&gt;(0);
  
  public Members() {
  }
  
  public Members(int memberId) {
      this.memberId = memberId;
  }
  public Members(int memberId, String userName, String password, String fullName, String email, String address, String gender, String dateOfBirth, String memberType, Set&lt;Cart&gt; carts) {
     this.memberId = memberId;
     this.userName = userName;
     this.password = password;
     this.fullName = fullName;
     this.email = email;
     this.address = address;
     this.gender = gender;
     this.dateOfBirth = dateOfBirth;
     this.memberType = memberType;
     this.carts = carts;
  }
  
  public int getMemberId() {
      return this.memberId;
  }
  
  public void setMemberId(int memberId) {
      this.memberId = memberId;
  }
  public String getUserName() {
      return this.userName;
  }
  
  public void setUserName(String userName) {
      this.userName = userName;
  }
  public String getPassword() {
      return this.password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  public String getFullName() {
      return this.fullName;
  }
  
  public void setFullName(String fullName) {
      this.fullName = fullName;
  }
  public String getEmail() {
      return this.email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  public String getAddress() {
      return this.address;
  }
  
  public void setAddress(String address) {
      this.address = address;
  }
  public String getGender() {
      return this.gender;
  }
  
  public void setGender(String gender) {
      this.gender = gender;
  }
  public String getDateOfBirth() {
      return this.dateOfBirth;
  }
  
  public void setDateOfBirth(String dateOfBirth) {
      this.dateOfBirth = dateOfBirth;
  }
  public String getMemberType() {
      return this.memberType;
  }
  
  public void setMemberType(String memberType) {
      this.memberType = memberType;
  }
  public Set&lt;Cart&gt; getCarts() {
      return this.carts;
  }
  
  public void setCarts(Set&lt;Cart&gt; carts) {
      this.carts = carts;
   }
  }
  </code></pre>
  
  <p>Products.java</p>
  
  <pre><code>package model;
  
  import java.util.HashSet;
  import java.util.Set;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity(name="products")
  public class Products  implements java.io.Serializable {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO) 
  private int productId;
  private String productName;
  private String productType;
  private String description;
  private Double price;
  private String productColor;
  private String productBrand;
  private String productSize;
  private Integer allProductsQuantity;
  private Set&lt;Cart&gt; carts = new HashSet&lt;Cart&gt;(0);
  
  public Products() {
  }
  
  public Products(int productId) {
      this.productId = productId;
  }
  public Products(int productId, String productName, String productType, String      description, Double price, String productColor, String productBrand, String productSize,  Integer allProductsQuantity, Set&lt;Cart&gt; carts) {
     this.productId = productId;
     this.productName = productName;
     this.productType = productType;
     this.description = description;
     this.price = price;
     this.productColor = productColor;
     this.productBrand = productBrand;
     this.productSize = productSize;
     this.allProductsQuantity = allProductsQuantity;
     this.carts = carts;
  }
  
  public int getProductId() {
      return this.productId;
  }
  
  public void setProductId(int productId) {
      this.productId = productId;
  }
  public String getProductName() {
      return this.productName;
  }
  
  public void setProductName(String productName) {
      this.productName = productName;
  }
  public String getProductType() {
      return this.productType;
  }
  
  public void setProductType(String productType) {
      this.productType = productType;
  }
  public String getDescription() {
      return this.description;
  }
  
  public void setDescription(String description) {
      this.description = description;
  }
  public Double getPrice() {
      return this.price;
  }
  
  public void setPrice(Double price) {
      this.price = price;
  }
  public String getProductColor() {
      return this.productColor;
  }
  
  public void setProductColor(String productColor) {
      this.productColor = productColor;
  }
  public String getProductBrand() {
      return this.productBrand;
  }
  
  public void setProductBrand(String productBrand) {
      this.productBrand = productBrand;
  }
  public String getProductSize() {
      return this.productSize;
  }
  
  public void setProductSize(String productSize) {
      this.productSize = productSize;
  }
  public Integer getAllProductsQuantity() {
      return this.allProductsQuantity;
  }
  
  public void setAllProductsQuantity(Integer allProductsQuantity) {
      this.allProductsQuantity = allProductsQuantity;
  }
  public Set&lt;Cart&gt; getCarts() {
      return this.carts;
  }
  
  public void setCarts(Set&lt;Cart&gt; carts) {
      this.carts = carts;
   }
  }
  </code></pre>
  
  <p>Cart.java</p>
  
  <pre><code>package model;
  
  public class Cart  implements java.io.Serializable {
  
  
   private int cartId;
   private Members members;
   private Products products;
   private Integer cartQuantity;
  
   public Cart() {
   }
  
  
  public Cart(int cartId) {
      this.cartId = cartId;
  }
  public Cart(int cartId, Members members, Products products, Integer cartQuantity) {
     this.cartId = cartId;
     this.members = members;
     this.products = products;
     this.cartQuantity = cartQuantity;
  }
  
  public int getCartId() {
      return this.cartId;
  }
  
  public void setCartId(int cartId) {
      this.cartId = cartId;
  }
  public Members getMembers() {
      return this.members;
  }
  
  public void setMembers(Members members) {
      this.members = members;
  }
  public Products getProducts() {
      return this.products;
  }
  
  public void setProducts(Products products) {
      this.products = products;
  }
  public Integer getCartQuantity() {
      return this.cartQuantity;
  }
  
  public void setCartQuantity(Integer cartQuantity) {
      this.cartQuantity = cartQuantity;
  }
  
  }
  </code></pre>
  
  <p>I add service also for this classes.</p>
  
  <p>MemberService</p>
  
  <pre><code>package service;
  
  import java.util.List;
  import model.Members;
  
  public interface MembersService {
      public void add(Members members);
      public void edit(Members members);
      public void delete(int memberId);
      public Members getMembers(int memverId);
      public List getAllMembers();
  }
  </code></pre>
  
  <p>ProductsService</p>
  
  <p>package service;</p>
  
  <pre><code>import java.util.List;
  import model.Products;
  
  public interface ProductsService {
      public void add(Products products);
      public void edit(Products products);
      public void delete(int productId);
      public Products getProducts(int productId);
      public List getAllProducts();
  }
  </code></pre>
  
  <p>Also add ServiceImpl</p>
  
  <p>MembersServiceImpl</p>
  
  <pre><code>package service;
  
  import DAO.MembersDAO;
  import java.util.List;
  import javax.jms.Session;
  import javax.transaction.Transactional;
  import model.Members;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  import org.springframework.stereotype.Service;
  
  @Service
  public class MembersServiceImpl implements MembersService{
  
  @Autowired
  private MembersDAO membersDAO;
  
  @Transactional
  public void add(Members members) {
      membersDAO.add(members);
  }
  
  @Transactional
  public void edit(Members members) {
      membersDAO.edit(members);
  }
  
  @Transactional
  public void delete(int productId) {
      membersDAO.delete(productId);
  }
  
  @Transactional
  public Members getMembers(int productId) {
      return membersDAO.getMembers(productId);
  }
  
  @Transactional
  public List getAllMembers() {
      return membersDAO.getAllMembers();
  }
  
  }
  </code></pre>
  
  <p>ProductsServiceImpl</p>
  
  <pre><code>package service;
  
  import DAO.ProductsDAO;
  import java.util.List;
  import javax.jms.Session;
  import javax.transaction.Transactional;
  import model.Products;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  import org.springframework.stereotype.Service;
  
  @Service
  public class ProductsServiceImpl implements ProductsService{
  
  @Autowired
  private ProductsDAO productsDAO;
  
  @Transactional
  public void add(Products products) {
      productsDAO.add(products);
  }
  
  @Transactional
  public void edit(Products products) {
      productsDAO.edit(products);
  }
  
  @Transactional
  public void delete(int productId) {
      productsDAO.delete(productId);
  }
  
  @Transactional
  public Products getProducts(int productId) {
      return productsDAO.getProducts(productId);
  }
  
  @Transactional
  public List getAllProducts() {
      return productsDAO.getAllProducts();
  }
  
  }
  </code></pre>
  
  <p>And ProductsContoller</p>
  
  <pre><code>package controller;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import model.Products;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.validation.BindException;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.SimpleFormController;
  import service.ProductsService;
  
  public class ProductsController extends SimpleFormController {
  
  public ProductsController() {
  
      setCommandClass(Products.class);
      setCommandName("products");
      setSuccessView("products");
      setFormView("products");
  }
  
   protected ModelAndView products(HttpServletRequest request, HttpServletResponse   response, Object command, BindException errors) throws Exception {
      Products products = (Products) command;
      ModelAndView mv = new ModelAndView(getSuccessView());
      /*ModelAndView addObject = mv.addObject("products",     ProductsService.ProductsService(products.getValue()));*/
      return mv;
  }
      @Autowired
      private ProductsService productsService;
      public void setProductsService(ProductsService productsService) {
          this.productsService = productsService;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here I am stack. </p>
  
  <p>I also have simple MembersDAO.java, ProductsDAO.java and there implementations.</p>
  
  <p>...and fist question is how to connect two .jsp pages? 
  How to make simple navigation bar to connect first all my .jsp(view) pages?
  To make simple nav bar on header and use on all my pages.
  I know i should use spring contorollers...</p>
  
  <p>How to make simple controller that will take me to all_products.jsp from index.jsp and list all products from products table from mysql database???</p>
  
  <p>How to import spring security, log in section in my app?
  Also add new product form... </p>
  
  <p>My app is working and deplopying...
  I can upload web.xml and servlet.xml but did change things...</p>
  
  <p>Can anyone help me?!
  Thank you very much.</p>