I am trying to figure out how to most effectively reuse JSP code.
I love the way Rails/erb works in that way … with yield, layout, content_for
Example:
main_layout.erb.html
<html>
<head><%= yield :head %></head>
<body><%= yield %></body>
</html>
use
<% content_for :head do %>
<title>A simple page</title>
<% end %>
<p>Hello, Rails!</p>
in controller
layout "main_layout"
What is the closest I can get to this with JSP (without using extra frameworks)? I know about JSP include but that’s not really the same as yield.
Any suggestions?
Thanks
I’m not familiar with what
yieldandcontent_forprovide, but JSP tag files allow you a more robust way to template pages than JSP includes.Example:
layout.tag
An individual JSP
Just place your layout.tag in the /WEB-INF/tags directory. You can use any available prefix you want, I just used “z” for the example.