ciao!
grazie per la risposta.
ho seguito il tuo consiglio, non ci avevo minimamente pensato avendo ripreso il codice da un altro progetto.
ho fatto al volo un bean apposito:
codice:
public class BookBean {
private int id;
private String title;
private String author;
private String editor;
private double price;
private String isbn;
private String note;
public BookBean(int id, String title, String author, String editor, double price, String isbn, String note) {
this.id = id;
this.title = title;
this.author = author;
this.editor = editor;
this.price = price;
this.isbn = isbn;
this.note = note;
}
public String getTitle() {
return title;
}
..................
}
nel controller:
codice:
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Locale locale, Model model) throws MalformedURLException, IOException {
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate);
Gson gson = new Gson();
JsonParser parser = new JsonParser();
ArrayList<BookBean> list = new ArrayList<>();
try (BufferedReader bf = new BufferedReader(new InputStreamReader(new URL("........").openStream()))) {
JsonArray jarray = parser.parse(new JsonReader(bf)).getAsJsonArray();
for (JsonElement e : jarray) {
Book book = gson.fromJson(e, Book.class);
list.add(new BookBean(book.id, book.title, book.author, book.editor, book.price, book.isbn, book.note));
}
}
model.addAttribute("books", list);
return "home";
}
nella jsp:
codice:
<c:if test="${not empty books}">
<ul>
<c:forEach var="book" items="${books}">
<li>${book.title}</li>
</c:forEach>
</ul>
</c:if>
cosi funziona.
grazie!!