2011-09-20 59 views
2

我有一个Struts操作类,它将自定义JSP标记的标记设置为String作为请求属性。动作类将其转发给一个JSP页面,该页面包含打印请求属性的另一个标签。但是,自定义JSP标记未被解析并显示为纯文本。下面显示JSP如何呈现它:如何评估存储在字符串中的JSP标记?

<%@ taglib uri="/tld/CdrReconTags.tld" prefix="reconTags" %> 

<reconTags:renderHTML> 
    <form id=F_3_2> 

    <table align='center' width='100%' style='border:1px solid black;' cellpadding='0' cellspacing='0'> 
     <tr> 
     <td colspan='2'>&nbsp;</td> 
     </tr> 
     <tr> 
     <td align='center'> 
      <div class='label'> 
      <strong style='white-space: nowrap;'>STARTDATE :&nbsp;</strong> 
      </div> 
     </td> 
     <td> 
      <div class='label'> 
      <strong style='white-space: nowrap;'> 
       <reconTags:reportDatesDropDown id="STARTDATE_3_3" />&nbsp; 
       <span style='color:red;font-weight: bold; font-size: 20px;'>*</span> 
      </strong> 
      </div> 
     </td> 
     <td align='center'> 
      <div class='label'> 
      <strong style='white-space: nowrap;'>ENDDATE :&nbsp;</strong> 
      </div> 
     </td> 
     <td> 
      <div class='label'> 
      <strong style='white-space: nowrap;'> 
</reconTags:renderHTML> 

请注意未解析的自定义JSP标记<reconTags:reportDatesDropDown id="STARTDATE_3_3" />。我如何让JSP评估它?以下代码是<reconTags:renderHTML>的标记处理程序,不会评估正文,如上面的输出中所示。

public class DynamicHTMLRendererTagHandler extends BodyTagSupport 
{ 

    private static final long serialVersionUID = 6457283471933854138L; 

    public int doStartTag() throws JspException 
    { 
     return EVAL_BODY_BUFFERED; 
    } 

    public int doAfterBody() throws JspException 
    { 
     /* Grab the body content */ 
     BodyContent body = this.getBodyContent(); 

     try 
     { 
      body.writeOut(body.getEnclosingWriter()); 
     } catch (IOException e) 
     { 
       throw new JspTagException(e.toString());  
     } 
     return SKIP_BODY; 
    } 
} 

回答

2

是reconTag应与最初的代码本身,而不是被添加为一个字符串输出...

请注意,所谓JSP做的是:

1 - 解析文档为标签。

2 - 填充文档请求的Java输出。

由于此调用仅在解释标签后完成,因此这些标签以纯文本出现是正常的。

如果你想添加一些动态标签到你的文档中,你将不得不找出一种方法,在解析之前使用这些标签来构建文档......然而,这可能是一个巨大的头痛,如果不是不可能的话。

+0

Gonçalo,Balusc:谢谢你的建议 –