I need a clarification on this below technology
Current technology: Struts 1.2 Jsp Java AngularJS
Currently I am trying to migrate one of my jsp page to AngularJS page which is client req.
I am trying using below code to get json response, but I unable to get the json data in my jsp page.
Question: 1) How to get a json object from the response of action class in struts?
2) Currently : Note: one of temporary way I able to get json object in jsp using session.setAttribute() and getAttribute.. but its not rite way to do it as I just getting all my table data and put in session. apart from this any way please help..
Code : In jsp:
$scope.getDataFromServer = function() {
$http({
method : 'GET',
url : '/com/test/Browse.do'
}).then (function successCallback(response) {
var itemsDetails = JSON.parse(response);
$scope.person = response;
}).error(function(data, status, headers, config) {
});
};
**//The above response getting as object unable to get json object.**
In action class:
public void doExecute(ActionContext ctx) throws IOException,
ServletException {
PersonData personData = new PersonData();//[PersonData class available]
personData.setFirstName("Mohaideen");
personData.setLastName("Jamil");
String json = new Gson().toJson(personData);
ctx.forwardToInput();
}
I able to get the data using session attribute like below, but it is not rite way will make me to avoid struts action and also whole table data putting in session I not sure whether it will rite way or secure way. var data1 = '<%=session.getAttribute("jsonobjtest")%>';
Can please help me out to get the rite way to implement with struts 1.2 and angularjs? if we cannot do it help me guide me the workaround how to achieve with angularjs?
Hie there from my understanding you want to get a json object from your Java backend here is how i do http requests in AngularJs 1.5.11
(function () {
'use strict';
angular.module("myapp")
.controller("HelloController", function($scope,$http){
$scope.getDataFromServer = function() {
$http.get("/com/test/Browse.do").success(function(response,status){
//console.log(response,status); check your data
$scope.person = JSON.parse(response);
});
}
});