形式没有在struts2的angularjs中正确提交

时间:2015-11-16 09:48:41

标签: javascript angularjs struts2 angularjs-http angularjs-forms

我正在使用带有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>

这是我的Action类。

package com.skilrock.Action;

import com.opensymphony.xwork2.ActionSupport;

public class 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;
}

}

我的重置按钮工作正常但是当我点击提交按钮有一个空表单然后它调用给定的动作类的方法..其他点是每次表单是空的或不是动作方法没有获取值形式......

0 个答案:

没有答案