Is there a jsp/jstl equivalent of this Rails error flash?
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<%- end -%>
I've been looking for a pre-built solution that is as simple as this Rails idiom.
You can use JSTL
c:forEach
to iterate over aMap<String, String>
. Every iteration gives you aMap.Entry
which in turn hasgetKey()
andgetValue()
methods. Assuming that you've put it in the request scope by keymessages
, here's an example:By the way, JSP/JSTL is not really comparable to the RoR MVC framework. JSP/JSTL is pretty low-level and offers practically no useful abstractions/facilities out of the box to represent a decent MVC approach. You may want to take a look for JSF 2.0 instead. It's the Java EE provided MVC framework. JSP is just a view technology. JSTL is just a standard flow/function/format taglib. Here's a JSF 2.0 tutorial.