2012-01-05 3 views
0

매우 간단한 JSP 2.0 태그를 정의하고 싶지만 수행 방법을 모른다.이 간단한 jsp 2.0 태그를 정의하는 방법

태그는 시스템에서 article 개체의 정보를 가져 오는 데 사용됩니다. 그리고 그것은 매우 간단합니다

<sys:article id="123" var="article"> 
    Title: ${aritcle.title} 
</sys:article> 

그럼 난 WEB-INF/tags/에서 article.tag라는 이름의 파일을 생성, 내용은 다음과 같습니다

<% 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 /> 

나는 몸에 검색된 문서 객체를 설정하는 방법을 알고하지 않으며, 그것의 제목을 보여주십시오.

답변

0

태그 파일에있는 키는 variable입니다.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 

<%@ attribute 
    name="id" 
    required="true" 
    description="the id of article" %> 

<%@ attribute 
    name="var" 
    required="true" 
    rtexprvalue="false" 
    description="the article object used by invoker" %> 

<%@ variable 
    name-from-attribute="var" 
    description="The alias of passed 'var'" 
    alias="aaa" 
%> 

<% 
Article article = getArticleById(id); 
request.setAttribute("article", article); 
%> 

<c:set var="aaa" value="${article}" /> 
관련 문제