• Post Reply Bookmark Topic Watch Topic
  • New Topic

forEach ArrayList of Objects

 
Mike Tabak
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.
 
Akhil Pratap Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using instead of just ${movie.name}
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
 
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
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!