stringcomtag.java
来自「移动彩信管理平台」· Java 代码 · 共 111 行
JAVA
111 行
package com.my7g.zj.mobile.mms.web.tag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
/**
* @author zhangyu
*
*/
public class StringComTag extends BodyTagSupport {
/**
*
*/
private static final long serialVersionUID = 8577436858020970840L;
/**将手机号码中的号码隐藏
*
*/
protected String name = null; //原始值
private int begin = 0; //开始位置
private int length = 0; //长度
private String str = "*"; //替换字符
private String color = null; //替换颜色
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getBegin() {
return begin;
}
public void setBegin(int begin) {
this.begin = begin-1;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public int doStartTag() throws JspException{
// TODO Auto-generated method stub
JspWriter out = pageContext.getOut();
try {
if (getBegin() >= getName().length() || getBegin() < 0){
out.append("起始长度超出范围");
return (SKIP_BODY);
}
String finname = getName().substring(0, getBegin());
if (getColor() != null || "null".equals(getColor()))
finname += "<font color=" + getColor() + ">";
setLength(getBegin() + getLength() > getName().length() ? getName().length() - getBegin() : getLength());
for (int i = 0; i < length; i++) {
finname += getStr();
}
if (getColor() != null || "null".equals(getColor()))
finname += "</font>";
if (getBegin() + getLength() <= getName().length()){
finname += getName().substring(getBegin() + getLength());
}
out.append(finname);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (SKIP_BODY);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?