鉴于我在 JSP 上有这样的东西:
<cic:table listBeanParm="presbeans" showSelct="false" messageType="cicProductTable">
<cic:column>
<cic:title>A column title</cic:title>
</cic:column>
</cic:table>
....
<% TableModel tableModel = (TableModel)request.getAttribute( "cic.table.model"); %>
//tableModel used here
我可以看到,在与之关联的代码中cic:table
,它设置了属性“cic.table.model”(障碍:我必须反编译才能看到它......没有源代码)。
public int doEndTag() throws JspException {
/* 47*/ request.setAttribute("cic.table.model", tableModel);
/* 48*/ init();
/* 49*/ return super.doEndTag();
}
看起来类型层次结构如下所示:
cicTable extends cicComponent
cicComponent extends BodyTagSupport
(cicComponent runs pageContext.getOut(), and we do not have a page!)
但即便如此,我尝试了几个这样的变体(doStartTag,doEndTag),但我的调用总是失败,编译类中出现空指针:
System.out.println("type:" + request.getAttribute("presbeans").getClass().getName());
cicTable aTable = new cicTable();
aTable.setListBeanParam("presbeans");
aTable.setShowSelect("false");
aTable.setMessageType("cicProductTable");
//int result = Integer.MAX_VALUE;
//try {result = aTable.doStartTag();} catch (Exception e) {System.out.println("doStartTag bombed: " + e.getMessage());}
//System.out.println("doStartTag returned " + result);
int result2 = Integer.MAX_VALUE;
result2 = Integer.MAX_VALUE;
try {result2 = aTable.doEndTag();} catch (Exception e) {System.out.println("doEndTag bombed: " + e.getMessage());}
// Always a null pointer on the line above
System.out.println("doEndTag returned " + result2);
TableModel tableModel = (TableModel)request.getAttribute( "cic.table.model");
我想做的是找到一种方法,将 JSP 页面上的标记库中发生的事情转换为将在 servlet 中运行的代码。 是否有标准的食谱方法来让 taglib 的东西在 Servlet 中运行?