java - How to write content before and after the output of a JSP -
i have jpss represent components. want have these component jsps write html before , after contents of jsp executed.
component.jsp
<@page session="false"> <%= "hello " + "world" %>
when jsp/servlet rendered, want render:
<div class="component"> hello world </div>
i want able create various "wrappers", , depending on jsp, include wrap contents of jsp correct content. if want change/augment wrapper down road, want in 1 place (could 100s of components).
can <@page extends="..."> possibly?
thanks
what want named: tag files. introduced on jsp 2.0
with approach can write jsp tags using jsp, therefore need create folder named web-inf/tags
, , create 'normal' jsp within folder.
the tag want create needs have following start instruction: <%@tag description="tag description" %>
in order indicate tag.
to use need reference tags want use following instruction: <%@ taglib tagdir="/web-inf/tags" prefix="custom"%>
so, can like: web-inf/tags/mytag.tag
<%@tag description="hello tag" %> <%@attribute name="name" required="false" type="java.lang.string"%> <html><head></head><body> <h1>hello <%=name%></h1> <jsp:dobody /> </body>
index.jsp
<%@ taglib tagdir="/web-inf/tags" prefix="custom"%> <custom:mytag name="my name">this content</custom:mytag>
the result page printing
<html><head></head><body> <h1>hello name</h1> content </body>
Comments
Post a Comment