JSP, can it work similar to yield, layout, content_for in Ruby/Rails/Erb

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



  <head><%= yield :head %></head>
  <body><%= yield %></body>


<% 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?



I'm not familiar with what yield and content_for provide, but JSP tag files allow you a more robust way to template pages than JSP includes.



<%@ tag body-content="scriptless" %>
<%@ attribute name="pageTitle" required="true" type="java.lang.String" %>


An individual JSP

<%@ taglib prefix="z" tagdir="/WEB-INF/tags" %>
<z:layout pageTitle="A simple page">
    <p>Hello, JSP!</p>

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.

Need Your Help

can I add “&” as in value of one field

php url query-string

I asked how can I add "&amp;" in value of one of the params

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.