简体   繁体   English

如何在jsp / servlet中的angular js中传递值

[英]how to pass value in angular js in jsp/servlet

I am developing a module in jsp/servlet in which i need to use angular js. 我在jsp / servlet中开发一个模块,在其中我需要使用angular js。 how could i pass the value from input box value in function then how to send value in servlet also...! 我如何从函数中的输入框值中传递值,然后又如何在servlet中发送值...!

Here the example of code:- 这里的代码示例:-

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
  <!DOCTYPE html>
  <html ng-app="mehandi" >
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>


      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js">  
     </script>
     <script>
        var app = angular.module('mehandi', []);
        app.controller('mhndiCtrl', function($http){
            var xyz = this;
            xyz.data = {}
            xyz.swati = function($http){


            }

        })


    </script>
  </head>
  <body ng-controller="mhndiCtrl as abc" >
    <h1>Hello World!</h1>
    <input type="text" ng-model="abc.data.myname">
    {{abc.data}}
    <button ng-click="abc.swati()" > </button>
   </body>
</html>

You can invoke the function via ng-init : in your html 您可以通过ng-init调用该函数:

ng-init="init('${userDTO.username}')"

So, in your *.js ng-controller it will be following: 因此,在您的* .js ng-controller中,它将如下所示:

$scope.init = function(username){
   /*logic code*/
};

Use the name attribute of input for servlets 将输入的名称属性用于servlet

<input type="text" name="firstname">

You can then retrieve it using 然后,您可以使用

request.getParameter("firstname")

The angular part remains the same 角部分保持不变

<input type="text" name="firstname" ng-model="abc.data.myname">

Remember, angularjs is a client side javascript framework, hence server side bindings remains the same. 请记住,angularjs是客户端javascript框架,因此服务器端绑定保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM