/**
* <bean:write ....../>定义此标签的类是org.apache.struts.taglib.bean.WriteTag如果对这个类扩展,加一个属性cut
* ,再根据cut的大小来截取标题的长度,我对WriteTag继承,重写doStartTag().
*/
package org.apache.struts.taglib.bean;//注意,要这样写,不然会出错的
import javax.servlet.jsp.JspException;
import org.apache.struts.taglib.TagUtils;
public class StringTag extends WriteTag {
private static final long serialVersionUID = 1L;
public int cut;
public String setValue(String value)
{
String tempProperty=value;
if(cut>0)
{
if(tempProperty.length()>=(cut+1)){
tempProperty=tempProperty.substring(0, cut) +"..."; }
}
return tempProperty;
}
public int doStartTag() throws JspException { // Look up the requested bean (if necessary)
if (ignore)
{
if (TagUtils.getInstance().lookup(pageContext, name, scope) == null)
{
return (SKIP_BODY); // Nothing to output
}
} // Look up the requested property value
Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
if (value == null)
{
return (SKIP_BODY); // Nothing to output
} // Convert value to the String with some formatting
String output = formatValue(value);
output=setValue(output); //这句是加的,别的都是原来的
//Print this property value to our output writer, suitably filtered
if (filter)
{
TagUtils.getInstance().write(pageContext, TagUtils.getInstance().filter(output));
}
else
{
TagUtils.getInstance().write(pageContext, output);
} // Continue processing this page
return (SKIP_BODY);}
public int getCut() {
return cut;
}
public void setCut(int cut) {
this.cut = cut;
}
}
资源引用:
http://hi.baidu.com/xgmlucky/blog/item/9acb8845a575313f869473a2.html