仅作代码记录之用
/WEB-INF/tags/section.tag
1 <%@ tag language="java" import="java.util.*,java.io.StringWriter" pageEncoding="UTF-8"%> 2 <%@ attribute name="name" type="java.lang.String" required="true" %> 3 <%-- <% 4 StringWriter writer = new StringWriter(); 5 getJspBody().invoke(writer); // 渲染标签体 6 String html = writer.toString(); 7 request.setAttribute(name, html); 8 %> --%>
layout.jsp
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 </head> 7 <body> 8 ${section_welcomeImage } 9 </body> 10 </html>
test.jsp
1 <my:section name="section_welcomeImage"> 2 2 <div id="welcomeImage"> 3 3 <img width="100%" height="150" src="<c:url value="/images/banner.jpg" />" alt="welcome"> 4 4 </div> 5 5 </my:section>