⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonbean.java

📁 有用JSP+JAVABEAN+ACCESS留言簿
💻 JAVA
字号:
/**
 * @(#)commonBean.java
 *
 *
 * @soiln 
 * @version 1.00 2007/12/20
 */
package com.web;

import java.text.*;
import java.util.Date;
import java.io.*;

public class commonBean
{

    public commonBean()
    {
    }

    public static String FilterSingleQuotes(String s)
    {
    	s = Replace(s, "'", "''");
    	return s;
    }
//替换成html标记
    public static String ReplaceHtml(String s)
    {
        s = Replace(s, "&", "&");
        s = Replace(s, "<", "&lt;");
        s = Replace(s, ">", "&gt;");
        s = Replace(s, "\t", "    ");
        s = Replace(s, "\r\n", "\n");
        s = Replace(s, "\n", "<br>");
        s = Replace(s, "  ", " &nbsp;");
        s = Replace(s, "'", "&#39;");
        s = Replace(s, "\\", "&#92;");
        return s;
    }
//去除html标记
    public static String RecoverHtml(String s)
    {
        s = Replace(s, "<br>", "\n");
        s = Replace(s, "&lt;", "<");
        s = Replace(s, "&gt;", ">");
        s = Replace(s, "&nbsp;", " ");
        return s;
    }
    
//显示中文
    public static String ShowCH(String s)
    {
    	if (s==null)
        return null;
        String s1="";
        try
        {
        	s1=new String(s.getBytes("ISO-8859-1"),"utf-8");
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return s;
        }
        return s1;

    }
//用于替换的函数
    public static String Replace(String s, String s1, String s2)
    {
        if(s == null)
        {
            return null;
        }
        StringBuffer stringbuffer = new StringBuffer();
        int i = s.length();
        int j = s1.length();
        int k;
        int l;
        for(k = 0; (l = s.indexOf(s1, k)) >= 0; k = l + j)
        {
            stringbuffer.append(s.substring(k, l));
            stringbuffer.append(s2);
        }

        if(k < i)
        {
            stringbuffer.append(s.substring(k));
        }
        return stringbuffer.toString();
    }
	//替换空的字符串为""
	public static String trim(String str) {
		return (str == null) ? "":str.trim();
	}
	//去掉字符串前面的空格
	public static String nullTrim(String str) {
		if (str == null) {
			return null;
		}
		String returnStr = str.trim();
		if (returnStr.length() == 0) {
			return null;
		}
		return returnStr;
	}
    //以2007-12-20的格式显示日期,参数为1时为yyyy-MM-dd,为其他数时为yyyy-MM-dd HH:mm:ss
	//◎Solin Yin(solin_y@163.com)
	public static String formatDate(String str, int i){
		SimpleDateFormat dateFormat;
		if (i == 1)
		{
			dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		}else
		{
			dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		}
        try{
		Date mtime = dateFormat.parse(str);
        str = dateFormat.format(mtime);
		}catch (Exception e){
			e.printStackTrace();
			str = str;
		}
		return str;
	}
    //题目显示时不超过规定的字节数 
	//◎Solin Yin(solin_y@163.com)
	public static String titleFormat(String str, int bt){
		int i = str.length();
		if(i > bt)
		{
			//bt = bt - 2;
			str = str.substring(0, bt)+"……";
		}else{
			str = str;
		}
		return str;
	}

	//删除文件 
	//◎Solin Yin(solin_y@163.com)
	public static String deleteFile(String path){
		String str;
		File file = new File(path);
		if (file.exists())
		{
		try
		{
			file.delete();
			str = "文件“"+path+"”删除成功!";
		}
		catch (Exception e)
		{
			str = e.toString();
		}
		}else{
			str = "文件“"+path+"”不存在!";
		}
		return str;
	}
	//判断文件大小,然后生成合理的大小值 
	//◎Solin Yin(solin_y@163.com)
	public static String fileSizeFormat(int i){
		String str;
		if (i < 1024)
		{
			str = Integer.toString(i);//转换为字符串
			str = str + " Byte";
		}else if (i < 1048576)
		{
			double j = (double)i/1024;
			str = new DecimalFormat(".00").format(j);//保留两位小数
			str = str + " KB";
		}else if (i >= 1048576)
		{
			double j = (double)i/1048576;
			str = new DecimalFormat(".00").format(j);//保留两位小数
			str = str + " MB";
		}else{
			str = "文件大小错误!";
		}
		return str;
	}
	//判断是否为管理员 
	//◎Solin Yin(solin_y@163.com)
	public static String adminFormat(String str){
		if (str.equals("super"))
		{
			str = "1";
		}else if (str.equals("common"))
		{
			str = "2";
		}else if (str.equals("1"))
		{
			str = "super";
		}else if (str.equals("2"))
		{
			str = "common";
		}else{
			str = null;
		}
		return str;
	}
	//判断是否超出字符限制 
	//◎Solin Yin(solin_y@163.com)
	public static String byteForm(String str, int i){
		if (str == null)
		{
			return "没有说明!";
		}
		if (i >= str.length())
		{
			  return str;
		}else{
			  return null;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -