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

📄 util.java

📁 JSP常用模块源代码之用户管理模块的全部源代码
💻 JAVA
字号:
package service;
import java.io.*;
import java.util.zip.*;

import org.apache.tools.zip.ZipEntry;
/**
 * @author myte
 *
 * 工具类
 */
public class Util {
	public static String OP_VIEW="0";//操作类型:查看
	public static String OP_ADD="1";//操作类型:添加
	public static String OP_EDIT="2";//操作类型:修改
	public static String OP_DELETE="3";//操作类型:删除
	
    public static int obj2int(Object n){//Object转整型
        if(null==n)
            return 0;
        else
            return Integer.valueOf(n.toString()).intValue();
    }    
    public static int str2int(String n){//字符串转整型
        if(n==null || n.trim().length()<=0)
            return 0;
        else
            return Integer.valueOf(n).intValue();
    }
    public static String sqlCheck(String str) {//过滤特殊字符,防SQL注入
		str = obj2str(str);
		str=str.replaceAll("'","");
		str=str.replaceAll(" ","");
		str=str.replaceAll("%","");
		return str;
	}
    public static String obj2str(Object str){//Object转字符串,null转空字符串
		if (null == str)
			return "";
		return str.toString();
    }
    public static String strToGBK(String source){//中文问题处理,转换GBK码
    	String strTarget = obj2str(source);
        if(source !=null){
        	try {
                byte[] temp1  =  source.getBytes("GBK");
	            if(source.equals(new String(temp1)))
	                strTarget = source;
	            else
	                strTarget = new String(source.getBytes("iso-8859-1"), "GBK");		
			} catch (Exception e) {
			}
          }
          return strTarget;
        }
    /**
     *<br>方法说明:实现文件的压缩处理
     *<br>输入参数:String fileName 压缩的文件
     *<br>返回类型:
     */
      public static void ZipFiles(String fileName){
       try{
         FileOutputStream f =
           new FileOutputStream(fileName+".zip");
         //使用输出流检查
         CheckedOutputStream cs = 
            new CheckedOutputStream(f,new Adler32());
          //声明输出zip流
          ZipOutputStream out =
            new ZipOutputStream(new BufferedOutputStream(cs));
          //写一个注释
          out.setComment("Upload Zipping");
          //对多文件进行压缩
            BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"ISO8859_1"));
             out.putNextEntry(new ZipEntry(fileName));
             int c;
             while((c=in.read())!=-1)
              out.write(c);
            in.close();
           //关闭输出流
           out.close();
        }catch(Exception e){
           System.err.println(e);
        }
      }
}

⌨️ 快捷键说明

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