bean:write之三 截取标题的长度的方法——类

 

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

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值