0

I have built a simple service in Spring:

@RequestMapping(value = "/list", method = RequestMethod.GET)
public @ResponseBody List<Person> eventList() throws ParseException {
    return personDAOImpl.list();
}

When I invoke the corresponding URL, I see a JsonObject list like this:

[{"id":2,"name":"John"},{"id":3,"name":"Jack"},{"id":4,"name":"Sam"}]

This service will be invoked both from a mobile app (and I know how to use a Json response in this case) and from a browser, and so I want that the /list service returns a Json.

By now, if I write the url in a browser (typing localhost:8080/myproject/eventList) I simply obtain the aforementioned Json String displayed on the screen.

How could I obtain a user-friendly interface that shows to the user a more friendly, like if I used a jsp?

ps: I have already used a service that successfully returns a jsp page (using ModelAndView), and that shows a table with the items, but I repeat that I would like to get a json response and than parsing it in a different way depending from the client (web browser or mobile app).

Thank you in advance!

Adriano Bellavita
  • 143
  • 1
  • 3
  • 12

1 Answers1

0

You could build a client app which makes requests to your API using JavaScript.

For example,

  1. localhost:8080/jsp/home returns a jsp page Home.
  2. The Home page makes AJAX request (using JavaScript) to localhost:8080/myproject/eventList and recieves the JSON object. jQuery.get()
  3. The Home page adds (using JavaScript) some visual elements to html. jQuery.append()

That's all.

Community
  • 1
  • 1