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

时间:2022-07-25 11:52:49

I am developing a module in jsp/servlet in which i need to use angular js. how could i pass the value from input box value in function then how to send value in servlet also...!

我在jsp / servlet中开发一个模块,我需要使用角度js。我如何在函数中传递输入框值的值,然后如何在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>

2 个解决方案

#1


1  

You can invoke the function via ng-init: in your html

您可以在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*/
};

#2


0  

Use the name attribute of input for servlets

使用servlet的输入的name属性

<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框架,因此服务器端绑定保持不变。

#1


1  

You can invoke the function via ng-init: in your html

您可以在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*/
};

#2


0  

Use the name attribute of input for servlets

使用servlet的输入的name属性

<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框架,因此服务器端绑定保持不变。