0

I have Java object with some fields

private static Film film;
    static  {
        film = new Film();
        film.setTitle("Inception");
        film.setYear(2010);
        film.setGenre("sci-fi");
        film.setWatched(true);

I want to display all fields on my jsp page and I using this construction

<body>
${film.toString()}
</body>

But it's not working and I get just empty page. How can I fix this? Or maybe use other way?

Controler

@RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView allFilms() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("films");
        modelAndView.addObject("film", film);
        return modelAndView;
2
  • Have you bound the variable to an attribute? Commented Jan 21, 2022 at 18:21
  • While the code you provided is correct, you need to provide more details. What do you mean by empty page? Does it just have an empty body or is it entirely empty? What HTTP code does the GET request return (check with curl)? Commented Jan 22, 2022 at 19:50

1 Answer 1

1

Problem was that I didn't add thymeleaf link to header xmlns:th="http://www.thymeleaf.org"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.