Logon.jsp
<!DOCTYPE html>
<html ng-app="angularspring">
<head>
</head>
<body ng-controller="LogonController">
<form>
<div>
TextBox : <input type="text" ng-model="person.userName" />
</div>
<div>
Password : <input type="password" ng-model="person.passWord" />
</div>
<div ng-view></div>
<button type="submit" ng-click="login(person)"> Submit
</button>
</form>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.i18n.properties-min-1.0.9.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/controller.js"></script>
<script type="text/javascript" src="js/i18n.js"></script>
<script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
controller.js
var as = angular.module('angularspring',[]);
as.controller('LogonController', function ($scope, $http) {
var actionUrl = 'action/checkUserNameAndPassword/';
$scope.login = function (person) {
$http.post(actionUrl,$scope.person);
};
});
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/action-servlet.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring MVC -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/action/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>logon.html</welcome-file>
</welcome-file-list>
action-servlet.xml ファイルには、以下のタグとクラスが含まれています
アクションサーブレット.xml
<mvc:annotation-driven/>
<context:annotation-config />
<context:component-scan base-package="com.pack" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix" value="" />
<property name="suffix" value=".html" />
</bean>
LogonController.java
LogonController では、個人オブジェクトにバインドされているリクエスト値を取得できますが、logonSuccess.html へのリクエストをレンダリングできません。
@RequestMapping(value = "/checkUserNameAndPassword", method = RequestMethod.POST)
@ResponseBody
public ModelAndView logon(@RequestBody Person person) {
return new ModelAndView("WEB-INF/views/logonSuccess");
}