Posts

Showing posts from March, 2018

Looping json array into javascript and jsp

Suppose i have json array .now i want to loop all object values in javascript Jsonarray is "jsonarr" I.e. For (int i=0;i<jsonarr.length;i++) { Var v=jsonarr[i]; Then v.name; }

How to pass dropdown selected values(list) as a parameter via Ajax to controller

in js file :     var sid= document.getElementById('mySelect'); var setitem= ""; for(i=0;i<sid.options.length;i++){       setitem= setitem+ sid.options[i].value + ","; } // Remove the last splitter setitem= setitem.substr(0,setitem.length-1); alert(setitem); Then pass the setitem to your data parameter in jQuery's AJAX. data: {        list: setitem,         }, while send convert the object type contentType: 'application/json; charset=utf-8',  data :JSON.parse(setitem) ; using parse method. or use JSON.stringify( setitem); Note: while data sending and receiving we should take care what kind of deta we are sending and accorind to that we should take care and make sure that same data type is defined 

How spring flow

Web.xml file is Written .will be load first and inside web.xml file we have one default file  will we load  Inside at least one servlet should be . Whatever the bean we are writing inside this file will be loaded at server startup or first User Request. i.e Connection beans ,database related beans,tx beans ..etc. For Spring Mvc dispatcherServlet have used -called front controller its take care all the user request and further process .How http request response will be process all stuff will handled by DS Servlet . Flow: Step  1 : first user request will be take by DispatcherServlet. Step  2 :  DS    will call and take the help of  HandlerMapping  and get to know the  Controller  class . Step  3 : And then controller will process the request by executing appropriate methods and return back the View using ModelAndView Step 4: Actual view will populated and Step  5 : Finally  DS  will pass the  Model  object to the  View  page to display the View with result on UI. Not

Ajax calling to controller

Ajax calling to controller method Sample Code: Desc: 1.>onbutton click  id = 'call' click, ajax() will call to states() method that defined in controller class . and getting response into 'Result' variable object and putting response into divID of <div> tag into body . <script type="text/javascript">         $(document).ready(function() {             $('#call').click(function ()   //'call is an ID of UI comp';               {                 $.ajax({                     type: "post",                     url: "./states", //Controller method                     data: “cname”:india,                     success: function(Result){                                  $('#divID).append(Result);                     }                 });             });   });     </script>     <title>Jsp file</title> </head> <body>     input:<input id="cname" type=&qu

Deal with @ResponseBody in Spring mvc

Ways to resolve views in Spring MVC Return a String with the view name and add attributes to the Model or ModelMap Return a ModelAndView with the view name and model Return an Object with a @ResponseBody annotation -when we want to return json/xml i.e. 3. @ResponseBody -it is an Spring annotation that dealt with ajax response  when we are using ajax call. @Requestmapping ( value = "/states" , method = RequestMethod . GET ) public @ResponseBody List < State > stateList () { return serviceImpl .getAllState (); }   OR   @RequestMapping(value="/states", method=RequestMethod.GET ,  produces={"application/json","application/xml"}) @ResponseBody public List<State> AllState() { return serviceImpl .getAllState () ; }

Java : Polymorphism

Polymorphism  : In java we can achieve polymorphism behaviour in two ways 1. Compile time 2.run time Compile time means object binding is done at compile time Run time means object bind at Execution time   Compile time means :method overloading Run time means :  method overriding Example :Mothod overloading Example  Class Employee {   public void m1(int a) {    S.O.P("int args"); }   public void m1(String str) {    S.O.P("String args"); } } Note: Method name is same but args is different

Java : Class object creation

This is about to provide the real time developments notes . Java: 1.How to write a class class Employee{ int id;     //for employee id String name;    //for employee name } 2. How to create a object of class  i.e Employee emp=new Employee(); Note emp is an object of class employee. 3.How to write a method in class i.e; Class Employee { public  void m1()   //m1 method has written { //logic  } } 4. How to call a method Fisrt create the object . then call the method as follow emp.m1(); 5. Example :complete example ------------------------------------------------------------------ class employee { int id; String name;  employee(int id,String name){ id=this.id; name=this.name; // } public void m1(){ system.out.println(" hello m1 method  calling ") ; } } //object creation and parameter calling Employee emp=new Employee();  ---------------------------------------------------------------