Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Karin Fernandez
12,670 PointsCountries of the world with Spring: flag images not showing
Hello, I'm working on the Countries of the World project, but I'm not able to get the images to show on the page. My images are under : src/main/resources/static/flags folder. On my index page, in order to show the image, this is what I did: <img th:src="@{'/flags/'+${country.countryImageName}+'.png'}" th:alt="@{${country.countryImageName}+'.png'}"/>
where country.countryImageName is the name of the flag, which I entered before. What is showing on the page is the alternative text, for example, as italy.png. So, this means that is taking the right name. What could be causing this?
I'm not sure how to post the code here, but the repository link is: https://github.com/karinfdez/countries_world_java_project
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Pointspost to Slack all techdegree related stuff...
more likely to find help
1 Answer
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsAdded a Pull Request with changes
All info is there.
So the problem is with the naming convention.
Because you write @RequestMapping("/flags/{countryName}") and use path to images "/flags/india.png"
Spring is confused where is the asset, i.e. image and where is actual link to detail page.
I changed link to "/country". Does it make sense ?
P.S. In later courses you see that for example Chris puts all static stuff under "/assets" folder to avoid confusions
Karin Fernandez
12,670 PointsKarin Fernandez
12,670 PointsOne more thing: I'm using Maven and working with Spring Tool Suite