Coming from a background in Django, I often use "template inheritance", where multiple templates inherit from a common base. Is there an easy way to do this in JSP? If not, is there an alternative to JSP that does this (besides Django on Jython that is :)
base template
{% block content %}{% endblock %}
basic content
{%extends"base template"%}{% block content %}
{{ content.title }}<--Fillsin a variable
{{ content.body }}<--Fillsin another variable {% endblock %}
Will render as follows (assuming that conten.title is "Insert Title Here", and content.body is "Insert Body Here")
EDIT: On a related note to tiles, you might want to look into Struts. It's not what you're looking for (that's tiles), but it is useful for someone coming from Django.
回答2:
You can do similar things using JSP tag files. Create your own page.tag that contains the page structure. Then use a tag to insert the contents.
回答3:
You can use rapid-framework for JSP template inheritance
Other options worth exploring include Sitemesh, which is built on the idea of page decorators, and Java Server Faces (JSF), which employs web-based UI components. And while we're talking about rapid development with web frameworks on the Java platform, I encourage you to check out Grails. It has the same mission has Django; namely, rapid web app development based on convention over configuration.
Hope that's not too many suggestion for one post. :o)
回答5:
My favorite Java web front-end tech is Facelets. It supports the most Django-like templating I've seen. It's not quite as clean as Django's, but you get the same inheritance benefits.
A comprehensive document could be found at http://www.playframework.org/modules/rythm. Though it's targeted to Play!Framework, most of the content also apply to pure rythm engine without Play!Framework.