Guest User

Untitled

a guest
Nov 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  3. <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
  4.  
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <title>JSP Page</title>
  10. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  11.  
  12. </head>
  13. <body>
  14. <nav class="navbar navbar-inverse">
  15. <div class="container-fluid">
  16. <div class="navbar-header">
  17. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
  18. <span class="icon-bar"></span>
  19. <span class="icon-bar"></span>
  20. <span class="icon-bar"></span>
  21. </button>
  22. <a class="navbar-brand" href="#">SpringCRUDDemo</a>
  23. </div>
  24. <div class="collapse navbar-collapse" id="myNavbar">
  25. <ul class="nav navbar-nav">
  26. <li><a href="<c:url value='/'/>">Home</a></li>
  27. <li><a href="<c:url value='/view/'/>">View</a></li>
  28. <li><a href="#">Update</a></li>
  29. <li><a href="#">Delete</a></li>
  30. </ul>
  31. <ul class="nav navbar-nav navbar-right">
  32. <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
  33. <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
  34. </ul>
  35. </div>
  36. </div>
  37. </nav>
  38.  
  39. <%@include file="./shared/header.jsp" %>
  40.  
  41. <div class="container">
  42. <form:form commandName="userData" action="#" method="post" enctype="multipart/form-data">
  43. <label for="firstname" class="label">Enter your first name</label>
  44. <form:input path="firstName"/>
  45. </form:form>
  46. </div>
  47.  
  48. package com.nishan.springcruddemo.servlet;
  49.  
  50. import com.nishan.springcruddemo.daoimp.CustomerDaoImp;
  51. import com.nishan.springcruddemo.entity.Customer;
  52. import java.sql.SQLException;
  53. import org.springframework.beans.factory.annotation.Autowired;
  54. import org.springframework.stereotype.Controller;
  55. import org.springframework.web.bind.annotation.ModelAttribute;
  56. import org.springframework.web.bind.annotation.RequestMapping;
  57. import org.springframework.web.bind.annotation.RequestMethod;
  58.  
  59. /**
  60. *
  61. * @author Dell
  62. */
  63. @Controller
  64.  
  65. public class DefaultController {
  66.  
  67. @Autowired
  68. CustomerDaoImp customerDaoImp;
  69.  
  70. @RequestMapping(value = "/", method = RequestMethod.GET)
  71. public String index() {
  72. return "index";
  73. }
  74.  
  75. @RequestMapping(value = "/insert", method = RequestMethod.POST)
  76. public String save(@ModelAttribute("userData") Customer customer) {
  77. try {
  78. customerDaoImp.insert(customer);
  79. } catch (ClassNotFoundException | SQLException ex) {
  80. System.out.println(ex.getMessage());
  81. }
  82.  
  83. return "redirect:/index";
  84. }
  85.  
  86. @RequestMapping(value = "/view", method = RequestMethod.GET)
  87. public String viewCustomer() {
  88. return "view-customer";
  89. }
  90. }
Add Comment
Please, Sign In to add comment