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


i trying figure out how reuse jsp code. love way rails/erb works in way ... yield, layout, content_for

example:

main_layout.erb.html

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

use

<% content_for :head %> <title>a simple page</title> <% end %>  <p>hello, rails!</p> 

in controller

layout "main_layout" 

what closest can jsp (without using frameworks)? know jsp include that's not same yield. suggestions?

thanks

i'm not familiar yield , content_for provide, jsp tag files allow more robust way template pages jsp includes.

example:

layout.tag

<%@ tag body-content="scriptless" %> <%@ attribute name="pagetitle" required="true" type="java.lang.string" %>  <html> <head>     <title>${pagetitle}</title> </head> <body>     <jsp:dobody/> </body> </html> 

an individual jsp

<%@ taglib prefix="z" tagdir="/web-inf/tags" %> <z:layout pagetitle="a simple page">     <p>hello, jsp!</p> </z:layout> 

just place layout.tag in /web-inf/tags directory. can use available prefix want, used "z" example.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -