Announcement Announcement Module
No announcement yet.
Connect JavaScript to Java using spring-MCV Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connect JavaScript to Java using spring-MCV

    I have the javascript on web page and Java Therad running. All is in spring-MVC framwork. My idea is that I have in jsp site javascript code. The controller make game therad wich be in java. But I need send data to my game thread. So I want to use controler for that.
    So I want from javascript script wich is in site call controler for update data and get responde from it.

    So I think to inputs code like this in my javascript code on site to send JSON data to controller.Example code to see idea:
        $("#btnPostGlEntry").click(function () {
            var glEntries = '{"glEntries":[{"generalLedgerId":"1"},{"accountId":"4"},{"amount":"344.44"},{"description":"Test Entry"},{"debit":"Yes"}]}';
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                url: contextPath + "/generalLedger/journalEntries/form",
                data : JSON.stringify(glEntries),
                success: function(data) {
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR + " : " + textStatus + " : " + errorThrown);


      var PersonText = '["firstname":"John", "lastname":"Someone"]';
        type : 'POST',
        url : "/",
        data : {'personModel' : personText},
        datatype : 'json',
        success : function(data) {
            var obj = jQuery.parseJSON(data);

    So the controller need some think like this:

      import org.springframework.stereotype.Controller;
        import org.springframework.ui.Model;
        import org.springframework.web.bind.annotation.*;
        public class TestController {
            public @ResponseBody Integer add(@RequestParam(value="inputNumber1", required=true) Integer inputNumber1,
                    Model model) {
                return inputNumber1;

    So I have a few questions.
    First. Javascript is a game code(graphic display in browser) wich is all time working. I want to calling controller and transfer data to it. And receive data from controller(physic engine). So I dont want any reload of page from controller action.
    Second. Is good idea making comunication by controller in this case?