This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

forEach ArrayList of Objects

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to access an array of "Movie" objects in my jsp. The array is loaded via org.springframework.web.servlet.ModelAndView.addObject(). Here is my jsp code:



The System.out.println("jsp page: .... &> results in the output: "jsp page: movielist - [Title: Die Hard; Budget: 20000000, Title: two days in paris; Budget: 1000000]" so I am confident the objects are being loaded into the ModelAndView correctly. However the output of the block is "${movie.name}" instead of the list of movies. My movie object has a getName() method to return a string (and a setName() method). I am not sure why the System.out.println statement can find the movielist attribute, but ${movie.name} is being treated a plain text. Thanks in advance for your help. There are no execptions thrown or other indications of errors.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using instead of just ${movie.name}
 
Marshal
Posts: 67417
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means that the EL is not being evaluated. Check that your web.xml is correctly being declared as the up-to-date version of the Servlet spec. (In other words, using XML Schema and not a DTD.)

This has nothing to do with your list, but with configuration.

Create a simple JSP that contains only ${3 + 4}

Until it displays 7 your config isn't correct.
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:That means that the EL is not being evaluated. Check that your web.xml is correctly being declared as the up-to-date version of the Servlet spec. (In other words, using XML Schema and not a DTD.)



That was exactly the problem! My web.xml was not configured properly. This was from an example in a book, Pro Spring Security. It built on earlier examples. The code changes were given but the author never mentioned to update the web.xml file from the earlier versions. It works fine now. Thank you very much!

Mike
 
Bear Bibeault
Marshal
Posts: 67417
173
Mac Mac OS X IntelliJ IDE jQuery Java
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Akhil Pratap Singh wrote:try using instead of just ${movie.name}



Thanks for your answer also.
 
Bear Bibeault
Marshal
Posts: 67417
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using <c:out> is important when the text is unknown (as in user input) to prevent injection attacks, and when the text is likely to contain characters that need encoding (like <).

It wouldn't help when the EL is disabled, but it's an important tag to use when appropriate.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic