我正在使用带有 angularjs 的 struts2 框架。有两个按钮,一个用于重置具有默认值的文本字段,另一个用于提交页面。我的提交不起作用。我的jsp页面是:-
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
</head>
<body ng-app="postApp" ng-controller="postController">
<div class="container">
<div class="col-sm-8 col-sm-offset-2">
<div class="page-header">
<h1>
Post data using angularJS
</h1>
</div>
<form name="studentForm" novalidate >
<div class="form-group">
<label>
Name
</label>
<input type="text" name="name" class="form-control"
ng-model="user.name" required>
<span ng-show="errorname">{{errorname}}</span>
</div>
<div class="form-group">
<label>
Username
</label>
<input type="text" name="username" class="form-control"
ng-model="user.username" required>
<span ng-show="errorUsername">{{errorUsername}}</span>
</div>
<div class="form-group">
<label>
Email
</label>
<input type="email" name="email" class="form-control"
ng-model="user.email" required>
<span ng-show="erroremail">{{erroremail}}</span>
</div>
<div><span><button ng-click="reset()" class="btn btn-primary">
reset
</button> </span>
<span> <button type="submit" ng-click="submitForm()" ng-disabled = {{erroremail}}
class="btn btn-primary">
Submit
</button></span>
</div>
</form>
</div>
</div>
<script>
var postApp = angular.module('postApp', []);
postApp.controller('postController', function($scope, $http) {
$scope.reset = function() {
$scope.user.name = "Mahesh";
$scope.user.username = "Parashar";
$scope.user.email = "MaheshParashar@gmail.com";
}
$scope.user = {};
$scope.submitForm = function() {
$http( {
method : 'POST',
url : '/angular/studentForm.action',
data : $scope.user,
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).success(function(data){
if (data.errors) {
$scope.errorname = data.errors.name;
$scope.errorUsername = data.errors.username;
$scope.erroremail = data.errors.email;
} else {
$scope.message = data.message;
}
}).error(function(data,status){
return false;
});
};
});
</script>
</body>
</html>
这是我的动作课。
package com.skilrock.Action;
导入 com.opensymphony.xwork2.ActionSupport;
公共类 StudentController 扩展 ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
private String firstName;
private String lastName;
private String email;
public String stdController() {
System.out.println(firstName + lastName + email);
return SUCCESS;
}
}
我的重置按钮工作正常,但是当我单击具有空表单的提交按钮时,它会调用给定操作类的方法。另一点是每次表单为空或不是该操作方法都没有获取表单的值...