如何使用角度JS访问servlet的表单数据 [英] how to access form data in servlet using angular js
问题描述
我是新来的角的js。请帮我跌破发行
我有一个表格与控制器的LoginController
。我有两个文本框 user.email
和 user.password的
。
我要发布的数据的servlet 的onclick
的登录在
按钮。
我写了下面的code,但是当我在点击日志,数据没有得到张贴到服务器。也没有错误消息。
I am new to angular js. please help me with the below issue
I have a form with a controller loginController
. I have two text boxes user.email
and user.password
.
I want to post the data to servlet onclick
of the Log in
button.
I have written the following code, but when i click Log in
, the data is not getting posted on to the server. Also there is no error message.
下面是我的JSP文件
`
Below is my JSP file `
<html ng-app="practiceApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel ="stylesheet" type="text/css" href="bootstrap.min.css"/>
</head>
<body>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="practice.js"></script>
<form name='login' ng-controller='loginController' ng-submit="login()">
<div>
{{hello}}
<label>Email</label>
<input type="email" name="email" ng-model="user.email" required/>
<span ng-show='login.email.$dirty && login.email.$error.required'>Required</span>
<span ng-show='login.email.$dirty && login.email.$error.email'>Not a valid email</span>
<label>Password</label>
<input type="password" name="password" ng-model="user.password" required/><br/>
<span ng-show='login.password.$dirty && login.password.$error.required'>Required</span>
<button ng-disabled="login.$invalid">Log in</button>
</div>
</form>
</body>
</html>
`
JavaScript文件
JavaScript File
`
var app = angular.module('practiceApp',[]);
app.controller('loginController',function($scope,$http){
$scope.login = function(){
$http({
method: 'POST',
url:'/login',
headers:{'Content-Type':'application/json'},
data:$scope.user
}).success(function(data){
$scope.status=data;
});
}
});
`
我已经尝试了所有可用,但找不到任何结果的解决方案..这个请帮助
` I have tried all the solutions that are available but couldn't find any result.. Kindly help on this
推荐答案
您&LT;按钮和GT;
不会导致表单提交。更改为&LT;输入类型=提交NG-禁用=登录$无效的。&GT;登录上述&lt; /按钮&GT;
或删除纳克 - 提交
从表单并添加 NG-点击=登陆()
到&LT;按钮&GT;
。
Your <button>
does not cause the form to submit. Change to <input type="submit" ng-disabled="login.$invalid">Log in</button>
or remove ng-submit
from the form and add ng-click="login()"
to the <button>
.
这篇关于如何使用角度JS访问servlet的表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!