登录.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>
控制器.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 文件中包含以下标签和类
动作-servlet.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>
登录控制器.java
在 LogonController 中,我能够获取绑定到 person 对象的请求值,但我无法将请求呈现给 logonSuccess.html
@RequestMapping(value = "/checkUserNameAndPassword", method = RequestMethod.POST)
@ResponseBody
public ModelAndView logon(@RequestBody Person person) {
return new ModelAndView("WEB-INF/views/logonSuccess");
}