How to simply return JSON from a JSP

后端 未结 3 1346
情话喂你
情话喂你 2020-12-08 12:26

Can anyone give me an example of how to return the following json simply from a jsp without any external libraries (except the ones that come standard with Oracle Java)?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 13:02

    This is the code:

    
        
            
            JSP Page
            
            
        
        
            

    Hello World!

    and this is the JSON:

    [
       {"label":"item 1", "value":"item 1", "id": 1},
       {"label":"item 2", "value":"item 2", "id": 2},
       {"label":"item 3", "value":"item 1", "id": 3}
    ]
    
    <%
       // Returns all employees (active and terminated) as json.
       response.setContentType("application/json");
    %>
    

提交回复
热议问题