How to pass a value of a variable from a java class to the jsp page

后端 未结 3 374
傲寒
傲寒 2020-12-31 19:28

I have 2 files named Admin.java and index.jsp.

In Admin.java through a function I retrieve the value of the varible named

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 19:55

    Seems like you're doing AJAX, so I'd say your response would need to be encoded in an AJAX-compatible way (JSON, XML, ...).

    If you do AJAX-encoding, your function might look like this:

    function(response)
    {
     var toplevel = response.;
    } 
    

    Edit:

    We're using JSON Simple for JSON encoding.

    Our Java backend then looks like this (simplified version without error checking):

    public String execute()
    {
      JSONObject jsonResult = new JSONObject();
    
      jsonResult.put( "result", "ok");
    
      return jsonResult.toJSONString();
    }
    

    And in the Javascript function:

    function(response)
    {
     var result = response.result; //now yields "ok"
    }
    

提交回复
热议问题