title: CRUD application in angularJs and struts2
body: <p>I want a simple CRUD application in struts2 and angularJs. </p>
  
  <p>I have tried for below code</p>
  
  <p>addTourController.js</p>
  
  <pre><code> var myapp = angular.module('myapp', []);
   myapp.controller('addTourCart', function($scope, $http){
   $scope.getDataFromServer = function(){
       var jouMObj={};
       var params = {
          "FromState" : $scope.TourFromState,
          "FromCity" : $scope.TourFromCity,
          "FromDate" : $scope.TourFromDate,
          "ToState" : $scope.TourToState,
          "ToCity" : $scope.TourToCity,
          "ToDate" : $scope.TourToDate,
          "Purpose" : $scope.purpose,
          "StayDetails" : $scope.TourStayMode
       };
       var data = angular.toJson(params);
       $http( {
              method : 'POST',
              url : 'addTourCart.action',
              data : 'value=' + data,
              headers : {
                  'Content-Type' : 'application/x-www-form-urlencoded'
              }
          }).success(function(data){
              $scope.jouMObj = data.jouMObj;
              alert(data.jouMObj);
              alert(params.FromDate);
       });
    }
   });
  </code></pre>
  
  <p>jsp page</p>
  
  <pre><code>   &lt;!DOCTYPE html&gt;
     &lt;html&gt;
     &lt;head&gt;
     &lt;meta charset="ISO-8859-1"&gt;
     &lt;title&gt;Tour&lt;/title&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"&gt;  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div ng-app="myapp"&gt;
            &lt;div id="divjourneydetail" ng-controller="addTourCart"&gt;
                      &lt;table id="table2" align="center"  cellpadding="0" cellspacing = "0"&gt;
                      &lt;tr&gt;
                          &lt;th&gt;&lt;b&gt;From&lt;/b&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;b&gt;To&lt;/b&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;b&gt;Travel Details&lt;/b&gt;&lt;/th&gt;
                          &lt;th&gt;Add / Reset&lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;strong&gt;State/City&lt;/strong&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;strong&gt;State/City&lt;/strong&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;strong&gt;Stay Detail&lt;/strong&gt;&lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="button" id="AddTourDtl" value="Add" ng-click="getDataFromServer()"/&gt;
                        &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;s:select name="TourFromState" id="TourFromState" list="statelist" listKey="stateCode" listValue="stateName" ng-model="TourFromState" headerKey="" headerValue="-Select State-" value="27" onchange="jFun_stateByCityList(this.value,'TourFromCity')"/&gt;
                              &lt;div id="tourReplaceCity"&gt;
                                  &lt;s:select name="TourFromCity" id="TourFromCity" list="citylist" listKey="regCd" listValue="distName" ng-model="TourFromCity"  headerKey="" headerValue="-Select City-" onchange="jFun_setNewCity(this.value,'getTourFromNewCity','NewTourFromCity')"/&gt;
                              &lt;/div&gt;
                              &lt;div id="getTourFromNewCity"&gt;&lt;/div&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="text" name="FromDate" id="TourFromDate" value=""  maxlength="10" ng-model="TourFromDate" &gt;
                              &lt;img src="&lt;%=request.getContextPath()%&gt;/MahBill/Images/calender_anim.gif" onClick="popupCalender('TourFromDate');"  width="19" height="19"  &gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;s:select name="TourToState" id="TourToState" list="statelist" listKey="stateCode" listValue="stateName" ng-model="TourToState" headerKey="" headerValue="-Select State-"value="27" onchange="jFun_stateByCityList(this.value,'TourToCity')"/&gt;
                              &lt;div id="tourReplaceToCity"&gt;
                                  &lt;s:select name="TourToCity" id="TourToCity" list="citylist" listKey="regCd" listValue="distName" ng-model="TourToCity" headerKey="" headerValue="-Select City-" onchange="jFun_setNewCity(this.value,'getTourNewCity','NewTourToCity')"/&gt;
                              &lt;/div&gt;
                              &lt;div id="getTourNewCity" &gt;&lt;/div&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="text" name="TourToDate" id="TourToDate" value="" maxlength="10"  ng-model="TourToDate" /&gt;
                              &lt;img src="&lt;%=request.getContextPath()%&gt;/MahBill/Images/calender_anim.gif" onClick="popupCalender('TourToDate');"  width="19" height="19"  &gt;
                          &lt;/td&gt;
                          &lt;td &gt;
                              &lt;s:textarea key="purpose" name="purpose" id="Tourpurpose" ng-model="purpose" cols="24" rows="2"/&gt; 
                          &lt;/td&gt;
                          &lt;td&gt;
                               &lt;s:select name="TourStayMode" id="TourStayMode" headerValue="- Select -" headerKey="" ng-model="TourStayMode"
                              list="staymodelist" listKey="staymodeid" listValue="staymodename" onchange="return jFun_stayMode(this.value);"/&gt;
                          &lt;/td&gt;
                     &lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;div id="cartTourDetails"&gt;
                      &lt;table id="table2" align="center"  cellpadding="0" cellspacing = "0"&gt;
                          &lt;tr&gt;
                              &lt;th align="center" colspan="2" style="border-right:1px solid #333;"&gt;&lt;b&gt;From&lt;/b&gt;&lt;/th&gt;
                              &lt;th align="center" colspan="2" style="border-right:1px solid #333;"&gt;&lt;b&gt;To&lt;/b&gt;&lt;/th&gt;
                              &lt;th align="center" colspan="2" style="border-right:1px solid #333;"&gt;&lt;b&gt;Travel Details&lt;/b&gt;&lt;/th&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;strong&gt;State/City&lt;/strong&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;strong&gt;State/City&lt;/strong&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;strong&gt;Stay Detail&lt;/strong&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr ng-repeat="journey in params"&gt;
                              &lt;td  valign="middle"&gt;
                                  {{FromState}}
                                  &lt;div id="tourReplaceCity"&gt;
                                      {{FromCity}}
                                  &lt;/div&gt;
                              &lt;/td&gt;
                              &lt;td&gt;{{FromDate}}&lt;/td&gt;
                              &lt;td valign="middle"&gt;
                                  {{ToState}}
                                  &lt;div id="tourReplaceToCity"&gt;
                                      {{ToCity}}
                                  &lt;/div&gt;
                              &lt;/td&gt;
                              &lt;td&gt;{{ToDate}}&lt;/td&gt;
                              &lt;td&gt;{{purpose}} &lt;/td&gt;
                              &lt;td&gt;{{ToDate}}&lt;/td&gt;
                         &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
                  &lt;/div&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>Struts.xml</p>
  
  <pre><code> &lt;package name="base" extends="json-default"&gt;
          &lt;action name="addTourCart" class="Action.Tour"  method="addTourCart"&gt;
              &lt;result type="json"&gt;
                  &lt;param name="root"&gt;jouMObj&lt;/param&gt;
              &lt;/result&gt;
          &lt;/action&gt;
   &lt;/package&gt;
  </code></pre>
  
  <p>Model Class </p>
  
  <pre><code>   public class JourneyDetail_M implements Serializable{
     private String FromState;
     private String FromCity;
     private String FromDate;
     private String ToState;
     private String ToCity;
     private String ToDate;
     private String staymodeid;
     private String staymodename;
     private String purpose;
      //getter and setter
  }
  </code></pre>
  
  <p>Action class</p>
  
  <pre><code>public class Tour extends ActionSupport {
      JourneyDetail_M jouMObj=new JourneyDetail_M();
  
  public String addTourCart(){
      try {
          System.out.println(request.getParameter("value"));
  
          String TourFromState=request.getParameter("FromState");
          String TourFromCity=request.getParameter("FromCity");
          String TourToState=request.getParameter("ToState");
          String TourToCity=request.getParameter("ToCity");
          String TourFromDate=request.getParameter("FromDate");
          String TourToDate=request.getParameter("ToDate");
          String purpose=request.getParameter("Purpose");
          String stayMode=request.getParameter("StayDetails");
  
          jouMObj.setFromState(TourFromState);
          jouMObj.setFromCity(TourFromCity);
          jouMObj.setFromDate(TourFromDate);
          jouMObj.setToState(TourToState);
          jouMObj.setToCity(TourToCity);
          jouMObj.setToDate(TourToDate);
          jouMObj.setPurpose(purpose);
          jouMObj.setStaymodeid(stayMode);
      } catch (IOException e) {
          e.printStackTrace();
          return "error";
      }
      return SUCCESS;
  }
  public JourneyDetail_M getJouMObj() {
      return jouMObj;
  }
  public void setJouMObj(JourneyDetail_M jouMObj) {
      this.jouMObj = jouMObj;
  }
  
   }
  </code></pre>
  
  <p>here is my code
  in action using request.getParameter("value") i got all value but how to set and get from action class?</p>