Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. @Autowired
  2. UserRegistrationDao userDao;
  3.  
  4. @RequestMapping(value = "/save", method = RequestMethod.POST)
  5. public ModelAndView saveUser(@ModelAttribute("userReg") UserRegistration userReg) {
  6. System.out.println("hi");
  7. userDao.registerUser(userReg);
  8. return new ModelAndView("redirect:/index.jsp");
  9. }
  10.  
  11.  
  12. my sample.js
  13.  
  14. var app = angular.module('ngMailChimp', []);
  15.  
  16. app.controller('SignUpController',[ '$scope', '$http', function($scope, $http) {
  17.  
  18. $scope.list = [];
  19. $scope.headerText = 'AngularJS Post Form Spring MVC example: Submit below form';
  20. $scope.submit = function() {
  21.  
  22. var formData = {
  23. "firstName" : $scope.ctrl.newCustomer.firstName,
  24. "lastName" : $scope.ctrl.newCustomer.lastName,
  25. "streetName" : $scope.ctrl.newCustomer.streetName,
  26. "aptName" : $scope.ctrl.newCustomer.aptName,
  27. "cityName" : $scopectrl.newCustomer.cityName,
  28. "stateName" : $scope.ctrl.newCustomer.stateName,
  29. "countryName" : $scope.ctrl.newCustomer.countryName,
  30. "zipName" : $scope.ctrl.newCustomer.zipName,
  31. "userName" : $scope.ctrl.newCustomer.userName,
  32. "password" : $scope.ctrl.newCustomer.password,
  33. };
  34.  
  35. var response = $http.post('save', formData);
  36. response.success(function(data, status, headers, config) {
  37. $scope.list.push(data);
  38. });
  39. response.error(function(data, status, headers, config) {
  40. alert( "Exception details: " + JSON.stringify({data: data}));
  41. });
  42.  
  43. $scope.list = [];
  44.  
  45. };
  46. }]);
  47.  
  48. <body ng-app="ngMailChimp" ng-controller="SignUpController as ctrl">
  49. <div class="signup-wrapper">
  50. <div class="logo">
  51. <img src="resources/assets/images/Untitled.png" alt="Logo"/>
  52. </div>
  53. <div class="alert alert-success message-animation" role="alert" ng-if="ctrl.showSubmittedPrompt">
  54. Thank you! Your account has been created.
  55. </div>
  56. <form name="ctrl.signupForm" ng-submit="submit()">/*ctrl.signup()*/
  57.  
  58. <div class="form-group" ng-class="{'has-error':ctrl.hasErrorClass('firstName')}">
  59. <label for="firstName"><strong>First Name</strong></label>
  60. <input id="firstName" name="firstName" class="form-control" type="text" required
  61. ng-model="ctrl.newCustomer.firstName" ng-model-options="{ updateOn : 'default blur' }"
  62. ng-focus="ctrl.toggleFirstNamePrompt(true)" ng-blur="ctrl.toggleFirstNamePrompt(false)"/>
  63.  
  64. <div class="my-messages">
  65. <div class="prompt message-animation" ng-if="ctrl.showFirstNamePrompt">
  66. Please Enter your First Name.
  67. </div>
  68. </div>
  69.  
  70. <div class="my-messages" ng-messages="ctrl.signupForm.firstName.$error" ng-if="ctrl.showMessages('firstName')">
  71. <div class="message-animation" ng-message="required">
  72. This field is required.<br>
  73. </div>
  74. </div>
  75.  
  76. <div class="form-group" ng-class="{'has-error':ctrl.hasErrorClass('lastName')}">
  77. <br><label for="lastName"><strong>Last Name</strong></label>
  78. <input id="lastName" name="lastName" class="form-control" type="text" required
  79. ng-model="ctrl.newCustomer.lastName" ng-model-options="{ updateOn : 'default blur' }"
  80. ng-focus="ctrl.toggleLastNamePrompt(true)" ng-blur="ctrl.toggleLastNamePrompt(false)"/>
  81.  
  82. <div class="my-messages">
  83. <div class="prompt message-animation" ng-if="ctrl.showLastNamePrompt">
  84. Please Enter your Last Name.
  85. </div>
  86. </div>
  87.  
  88. <div class="my-messages" ng-messages="ctrl.signupForm.lastName.$error" ng-if="ctrl.showMessages('lastName')">
  89. <div class="message-animation" ng-message="required">
  90. This field is required.<br>
  91. </div>
  92. </div>
  93. <button class="btn btn-primary" type="submit">Create My Account</button>
  94. </form>
  95. </div>
  96.  
  97. <beans xmlns="http://www.springframework.org/schema/beans"
  98. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
  99. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  100. xsi:schemaLocation="
  101. http://www.springframework.org/schema/beans
  102. http://www.springframework.org/schema/beans/spring-beans.xsd
  103. http://www.springframework.org/schema/mvc
  104. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  105. http://www.springframework.org/schema/context
  106. http://www.springframework.org/schema/context/spring-context.xsd">
  107.  
  108.  
  109. <context:component-scan base-package="org.weber.xxx.controller"></context:component-scan>
  110.  
  111.  
  112. <mvc:resources mapping="/resources/**" location="/resources/"
  113. cache-period="31556926" />
  114.  
  115.  
  116. <bean
  117. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  118. <property name="prefix" value="/WEB-INF/jsp/"></property>
  119. <property name="suffix" value=".jsp"></property>
  120. </bean>
  121.  
  122. <bean id="ds"
  123. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  124. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  125. <property name="url" value="jdbc:mysql://localhost:3301/weber" />
  126. <property name="username" value="root" />
  127. <property name="password" value="xxxx" />
  128. </bean>
  129.  
  130. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  131. <property name="dataSource" ref="ds"></property>
  132. </bean>
  133.  
  134. <bean id="userDao"
  135. class="org.weber.xxx.user.registration.dao.UserRegistrationDaoImpl">
  136. <property name="template" ref="jdbcTemplate"></property>
  137. </bean>
  138.  
  139. <servlet>
  140. <servlet-name>weber</servlet-name>
  141. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  142. <load-on-startup>1</load-on-startup>
  143. </servlet>
  144.  
  145. <context-param>
  146. <param-name>contextConfigLocation</param-name>
  147. <param-value>WEB-INF/weber-servlet.xml</param-value>
  148. </context-param>
  149.  
  150. <servlet-mapping>
  151. <servlet-name>weber</servlet-name>
  152. <url-pattern>/</url-pattern>
  153. </servlet-mapping>
  154. <listener>
  155. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  156. </listener>
  157. </web-app>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement