Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在单页应用程序中将输入值存储为java对象?_Javascript_Java_Html_Angularjs - Fatal编程技术网

Javascript 如何在单页应用程序中将输入值存储为java对象?

Javascript 如何在单页应用程序中将输入值存储为java对象?,javascript,java,html,angularjs,Javascript,Java,Html,Angularjs,我试图将html输入值作为java对象存储在单页应用程序中 在home.html中,我在输入值中输入了一些数据。当我采取行动时,我的地址显示为空。但如果我将其更改为“/helloDetails”,我将得到一个rest页面,并获得我输入的值。但这样做会刷新我的页面。我希望它路由到#/about页面,并让控制器检索地址(查看下面的控制器类) Home.HTML <div class="container-4"> <form action="#/about" method="G

我试图将html输入值作为java对象存储在单页应用程序中

在home.html中,我在输入值中输入了一些数据。当我采取行动时,我的地址显示为空。但如果我将其更改为“/helloDetails”,我将得到一个rest页面,并获得我输入的值。但这样做会刷新我的页面。我希望它路由到#/about页面,并让控制器检索地址(查看下面的控制器类)

Home.HTML

 <div class="container-4">
  <form action="#/about" method="GET">
    <input type="text" name="address" placeholder="Address..." "/>
    <button class="icon"  type="submit"><i class="fa fa-search"></i></button>
    </form>
  </div>
控制器

@RequestMapping("/helloDetails")
public Map<String, Object> data(Address address) throws MalformedURLException {
    Map<String, Object> model = new HashMap<String, Object>();         
    model.put("addid", address.getAddress());
    System.out.println(address.getAddress() + "Hello Details @@@@@");

  return model
}

这基本上会将用户输入的内容打印到输入框中。

@faffafff我的控制器是java。我的控制器可能出错。通常情况下,您会使用$http而不是通过表单将数据发送到服务器,
action=“#/about”
没有任何意义。将数据存储在服务中并使用
$location.path('/about')在收到数据后更改路线response@charlietfl我理解,用户必须输入值。如何存储用户作为服务输入的值?这是我应该关注的帖子吗?无论用户输入什么,都在其各自的
ng模型中。获取它,将其放入一个
JSON
中,并使用
$http
将其发送到javaapi。
@RequestMapping("/helloDetails")
public Map<String, Object> data(Address address) throws MalformedURLException {
    Map<String, Object> model = new HashMap<String, Object>();         
    model.put("addid", address.getAddress());
    System.out.println(address.getAddress() + "Hello Details @@@@@");

  return model
}
<div class="jumbotron text-center">
<h1>About Page</h1>

<p>{{ message }}</p>
<p> aa {{greeting.addid}} </p>
<form ng-submit="save()">
<input type="text" name="address"placeholder="Address..." ng-model="stack"/>
<button class="icon"  type="submit"><i class="fa fa-search"></i></button>
<p> hello this is : <span ng-bind="stack"></span></p>
App.controller('mainController', function($scope, $http) {

    var data=$scope.stack;
    $http.post('/helloDetails', data)
        .then(function(response){

        });