📄 formatfilesize.java
字号:
package com.dark.nethd.tags;
import java.text.Format;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.taglib.TagUtils;
public class FormatFileSize extends TagSupport {
private String name = null;
private String scope = null;
private String property = null;
private String format = "KB";
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public int doEndTag() throws JspException {
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
Integer filesize = 0;
if (format.equals("MB")) {
filesize = Integer.parseInt(value.toString()) / 1024 / 1024;
}
if (format.equals("KB")) {
filesize = Integer.parseInt(value.toString()) / 1024;
}
String output = filesize + format;
TagUtils.getInstance().write(pageContext, output);
return (SKIP_BODY);
}
public void release() {
super.release();
name = null;
property = null;
scope = null;
format = "KB";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -