【发布时间】:2016-10-14 06:07:32
【问题描述】:
我在带有 Java 的 MVC 中使用 AngularJs。我正在尝试将带有动作的经典表单更改为角度表单,但是在调用提交按钮后我无法加载新的 jsp。我该怎么做?
在成功事件中,我将 jsp 作为纯文本获取,但我不知道我必须用它做什么。非常感谢!
index.jsp
<body ng-app="myApp">
<form ng-controller="myController" ng-submit="login()">
<input type="text" id="name" name="name" ng-model="user.name" />
<input type="password" name="password" ng-model="user.password" />
<input type="submit" value="Acceder" />
</form>
</body>
index.js
var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {
$scope.login = function() {
$http({
method: 'POST',
url: 'http://localhost:8080/myApplication/Login',
headers: {'Content-Type': 'application/json'},
data: $scope.user
}).success(function (data) {
console.log(data); // --> "<html> <head><title>client</title></head>.... </html>"
});
};
});
LoginControllerServlet.java
public class LoginControllerServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
//...
RequestDispatcher rd = request.getRequestDispatcher("./client.jsp");
//...
rd.forward(request, response);
}
}
【问题讨论】: