Guillaume Guillaume - 1 year ago 94
AngularJS Question

[AngularJS][JavaEE] How to send multiple data with $

I work on a webapp, i have a probleme to send data and i didn't find some example. I use AngularJS and JavaEE.

Now :

AngularJs :

quiz is an object.

roomFactory.create = function(quiz){
//item.idLesson = $stateParams.lessonid;
return $"/api/private/room/create",quiz)
.then(function (response){ =;
},function (response){

Servlet :

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//get the identity of the one who send the request
Map<String, Object> payload = AppConfig.getRequestPayload(request);
//objetMapper --> use to add request....
ObjectMapper objectMapper = new ObjectMapper();

Random randomGenerator;
// Number of question for the two sets
int nbQuestion = 0;
List<Question> questionsRandom = new ArrayList<>();

//Get object from request

//List<String> list = objectMapper.readValue(AppConfig.getJsonRequest(request), new TypeReference<List<String>>(){});
//List<Quiz> list2 = objectMapper.readValue(AppConfig.getJsonRequest(request), new TypeReference<List<Quiz>>(){});
//String name = list.get(0);

Quiz quiz = objectMapper.readValue(AppConfig.getJsonRequest(request),Quiz.class);
if (quiz.getDuration() == null) {

//"getIdLesson : ");
//Get list of question from datastore
List<Question> questions = ofy().load().type(Question.class).filter("idLesson", quiz.getIdLesson()).list();

//Take some questions from the list to make the quiz
if (!questions.isEmpty()) {
if (questions.size() < quiz.getNbQuestion()) {
nbQuestion = questions.size();
} else {
nbQuestion = quiz.getNbQuestion();
// we peek all the question randomly to the server and create a list of question
while (nbQuestion > 0) {
randomGenerator = new Random();
int index = randomGenerator.nextInt(questions.size());

if (!questionsRandom.isEmpty()) {

//Set the quiz
Lesson lesson = ofy().load().type(Lesson.class).id(Long.valueOf(quiz.getIdLesson())).now();
//Lesson lesson = ofy().load().type(Lesson.class).filter("idLesson", quiz.getIdLesson()).first().now();

//SET the room
//User user = ofy().load().type(User.class).id(Long.valueOf(jsonUserId.toString())).now();

User user = ofy().load().type(User.class).filter("email", payload.get("email").toString()).first().now();

//"User : "+user.getFirstName());

Room room = new Room(user, quiz, 60);
room.setName(lesson.getTitle() + RoomManager.roomNumber);
room.setId(quiz.getIdLesson() + RoomManager.roomNumber);

//Save the room in RoomManager
RoomManager.addNewRoom(quiz.getIdLesson(), room);

//Send the room in response
String json = objectMapper.writeValueAsString(room);


I need another parameter in my fonction create :

roomFactory.create = function(quiz, roomName){

I try this to send both data :

return $"/api/private/room/create",quiz, roomName)


return $"/api/private/room/create",[quiz, roomName])

Get data in Servlet :

first solution :

String roomName= objectMapper.readValue(AppConfig.getJsonRequest(request),String.class);

second solution :

List<String> list = objectMapper.readValue(AppConfig.getJsonRequest(request), new TypeReference<List<String>>(){});

String roomName = list.get(0);
roomName = roomName.replace("\"", "");

but the second didn't work because quiz is an object. I try to convert quiz but i didn't work as well.

Answer Source

You can pass multiple Data as follow

var Indata = {'pram1': 'value1', 'pram2': 'value2' };
$"/api/private/room/create", Indata)
.then(function (response){ =;
    },function (response){

Here is the better example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download