JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»


public void setQuery(String query)


{


this.query = query;


}


public void setField(String field)


{


this.field = field;


}


public void setObject(Object o)


{


this.o = o;


}


public void setBean(String bean)


{


this.bean = bean;


}


public int doStartTag()


throws JspException


{


checkAttributes();


ResultSet rs = null; try {


zb



ite) {


rs = (ResultSet)pageContext.findAttribute(query); if(null != rs) {


Object []p = new Object[]{rs.getString(field)}; Method m =


BeanUtil.getSetPropertyMethod(o, property); m.invoke(o, p);


} else {


throw new NullPointerException();


}


return SKIP_BODY;


} catch(SQLException sqe) {


// Throw a JspTagException } catch(java.lang.IllegalAccessException iae) {


// Throw a JspTagException } catch(java.lang.NoSuchMethodException nme) {


// Throw a JspTagException } catch(j ava.lang.reflect.InvocationTargetException // Throw a JspTagException } catch(java.beans.IntrospectionException ie) {


// Throw a JspTagException


}


}


protected void checkAttributes() throws JspException


{


if(null == field) { field = property;


}


if(null == o) {


o = pageContext.findAttribute(bean); if(null == o) {


throw new NullPointerException();


}


}


}


protected void clearProperties() {


query = null; field = null; property = null; bean = null; o = null;


super.clearProperties();


}


}

О Takes a column value out of the ResultSet. This is the first action performed by the tag. e Sets the column value into a bean. This is the second action performed by the tag.


While it is important that a single tag perform one operation, this often isn’t the most efficient approach. As with many rules in real life, we can sometimes ignore this one (though we may sacrifice some advantages associated with obeying it).

Скачать в pdf «JSP Tag Libraries»