<html>
<head>
<title>Javascript Login Form Validation</title>
<link rel="stylesheet" href="css/style.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script>
angular.module("app",[])
.controller("ctrl", MyCtrl)
function MyCtrl($scope){
$scope.attempt = 3;
$scope.ctrlClickHandler = function(){
alert("Inside controller: value of myval is " + $scope.attempt--);
$scope.username = document.getElementById("username").value;
$scope.password = document.getElementById("password").value;
h.get("/controller/listEmployee").succsess(function(response){
$scope.Employees=response;
if ( $scope.username == $scope.Employees.empName && $scope.password == $scope.Employees.password){
alert ("Login successfully");
window.location = "index.html"; // Redirecting to other page.
return false;
}
else{
$scope.attempt --;// Decrementing by one.
alert("You have left "+attempt+" attempt;");
// Disabling fields after 3 attempts.
if( $scope.attempt == 0){
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
});
}
};
</script>
</head>
<body>
<div class="container">
<div class="main" ng-app="app" ng-controller="MyCtrl">
<form id="form_id" method="get" name="myform">
<label>User Name :</label>
<input type="text" name="username" id="username"/>
<label>Password :</label>
<input type="password" name="password" id="password"/>
<button type="button" ng-click="ctrlClickHandler()">Login</button>
</form></div></div></body></html>
Java method:
public String listEmployee() {
String SQL = "select * from employee";
List <Employee> employees = jdbcTemplateObject.queryForList(SQL);
return employees.toString();
}
任何人都可以将我的if条件代码更正为angularjs函数 ctrlClickHandler ,以便我可以调用其他页面。
h.get(&#34;的 /控制器/ listEmployee &#34)。succsess(功能(响应){ 的 $ scope.Employees =响应;
/ controller / listEmployee 它的一个java方法名称listEmployee包名称 controller 和listEmployee返回字符串见上面的方法: