I want to define a very simple JSP 2.0 tag, but don’t know how to do.
The tag is used to get the information of a article object in the system. And it’s very simple:
<sys:article id="123" var="article">
Title: ${aritcle.title}
</sys:article>
Then I created a file named article.tag under WEB-INF/tags/, the content is:
<% tag import="sys.App, sys.domains.*" %>
<%@ attribute
name="id"
type="java.lang.String"
required="true"
description="the id of an article" %>
<%@ attribute
name="var"
type="java.lang.String"
required="true"
description="let invoker use it to get information" %>
<%
Article article = App.articleDao.get(id);
%>
// how to set article to the body
<jsp:doBody />
I don’t know how to set the retrieved article object to the body, and let it show the title of it.
The key is
variablein the tag file.