`
jushi1988
  • 浏览: 78072 次
  • 性别: Icon_minigender_1
  • 来自: 黑龙江
社区版块
存档分类
最新评论

留言内容转换通用Bean

阅读更多

 

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, "", ">"); 
        s = Replace(s, "\t", "    "); 
        s = Replace(s, "\r\n", "\n"); 
        s = Replace(s, "\n", ""); 
        s = Replace(s, "  ", "  "); 
        s = Replace(s, "'", "'"); 
        s = Replace(s, "\\", "\"); 
        return s; 
    } 
//去除html标记 
    public static String RecoverHtml(String s) 
    { 
        s = Replace(s, "", "\n"); 
        s = Replace(s, "<", ""); 
        s = Replace(s, " ", " "); 
        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  bt) 
 { 
 //bt = bt - 2; 
 str = str.substring(0, bt)+"……"; 
 }else{ 
 str = str; 
 } 
 return str; 
 } 

 //删除文件 
 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; 
 } 
 //判断文件大小,然后生成合理的大小值 
 public static String fileSizeFormat(int i){ 
 String str; 
 if (i = 1048576) 
 { 
 double j = (double)i/1048576; 
 str = new DecimalFormat(".00").format(j);//保留两位小数 
 str = str + " MB"; 
 }else{ 
 str = "文件大小错误!"; 
 } 
 return str; 
 } 
 //判断是否为管理员 
 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; 
 } 
 //判断是否超出字符限制 
 public static String byteForm(String str, int i){ 
 if (str == null) 
 { 
 return "没有说明!"; 
 } 
 if (i >= str.length()) 
 { 
   return str; 
 }else{ 
   return null; 
 } 
 } 
}

 

 

分享到:
评论

相关推荐

    MyEclips+SSH留言板系统

    - **设计数据库表**:根据需求设计留言板的数据库表,如留言表(包括ID、用户名、留言内容、时间等字段)。 - **编写Model**:根据数据库表创建对应的Java实体类,并使用Hibernate的注解进行ORM配置。 - **编写...

    留言簿JSP 

    9. **JSTL(JSP Standard Tag Library)**:一套标准标签库,提供了各种通用的功能,如循环、条件判断、XML处理等,使代码更易读且减少Java代码的使用。 10. **Servlet生命周期**:JSP在运行时会被转换为Servlet,...

    jsp servlet 入门学习资料-新手一看就懂

    5.5 如何将一个普通的JSP文件转换为一个XML 文档 5.6 JSP1.1的DTD文件 第6章 JSP基础实例 6.1 第一个JSP程序—HelloWorld! 6.2 注释的使用 6.3 脚本元素 6.3.1 声明 6.3.2 表达式 6.3.3 脚本代码 6.4 page...

    jsp从入门到高级编程

    5.5 如何将一个普通的JSP文件转换为一个XML 文档 5.6 JSP1.1的DTD文件 第6章 JSP基础实例 6.1 第一个JSP程序—HelloWorld! 6.2 注释的使用 6.3 脚本元素 6.3.1 声明 6.3.2 表达式 6.3.3 脚本代码 6.4 page...

    JSP高级教程

    5.5 如何将一个普通的JSP文件转换为一个XML 文档 5.6 JSP1.1的DTD文件 第6章 JSP基础实例 6.1 第一个JSP程序—HelloWorld! 6.2 注释的使用 6.3 脚本元素 6.3.1 声明 6.3.2 表达式 6.3.3 脚本代码 6.4 page...

    JSP高级编程

    5.5 如何将一个普通的JSP文件转换为一个XML 文档 5.6 JSP1.1的DTD文件 第6章 JSP基础实例 6.1 第一个JSP程序—HelloWorld! 6.2 注释的使用 6.3 脚本元素 6.3.1 声明 6.3.2 表达式 6.3.3 脚本代码 ...

    Java开发技术大全 电子版

    7.2.6显示文件内容241 7.2.7文件的复制243 7.2.8顺序输入流244 7.2.9管道输入输出流246 7.2.10过滤输入输出流248 7.3Reader和Writer类使用249 7.3.1InputStreamReader类中的方法249 7.3.2OutputStreamWriter...

Global site tag (gtag.js) - Google Analytics