📄 valuetag.java
字号:
package cn.com.pkusoft.tag;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: pku-soft</p>
* @author weiming
* @version 1.0
*/
public class ValueTag
extends BodyTagSupport
{
private String name = null;
private String source = null;
private String filter = null;
public ValueTag()
{
}
public void setName(String name)
{
this.name = name;
}
public void setSource(String source)
{
this.source = source;
}
public Tag getParent()
{
/**@todo Implement this javax.servlet.jsp.tagext.Tag abstract method*/
throw new java.lang.UnsupportedOperationException(
"Method getParent() not yet implemented.");
}
public int doStartTag() throws JspException
{
return 0;
}
public int doEndTag() throws JspException
{
String bodyValue = "";
try
{
if (this.source != null)
{
Object contains = pageContext.getSession().getAttribute(this.
source);
if (contains instanceof Map)
{
Map containMap = (Map) contains;
Object bodyObject = containMap.get(this.name);
if (bodyObject == null)
{
bodyValue = "";
}
else
{
bodyValue = (String) bodyObject;
}
}
else if (contains instanceof Collection)
{
System.out.println("this not a Map!");
}
if (this.filter != null && this.filter.equals("true"))
{
bodyValue = this.filter(bodyValue);
}
pageContext.getOut().write(bodyValue);
}
}
catch (IOException ex)
{
throw new JspException(ex.getMessage());
}
return EVAL_PAGE;
}
private String filter(String strSrc)
{
StringBuffer buff = new StringBuffer(strSrc.length());
int length = strSrc.length();
for (int i = 0; i < length; i++)
{
char ch = strSrc.charAt(i);
switch (ch)
{
case '<':
buff.append("<");
break;
case '>':
buff.append(">");
break;
case '&':
buff.append("&");
break;
default:
buff.append(ch);
}
}
return buff.toString();
}
public void setFilter(String filter)
{
this.filter = filter;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -