`
收藏列表
标题 标签 来源
Oracle CreateUser oracle createuser
------------------------------------
--	以下操作在sys用户下执行		  --
------------------------------------

create user blog
       identified by blog
       default tablespace portaloneblog
       temporary tablespace portaloneblog_tmp
/
grant connect,resource,create any table,drop any table,create sequence, 
      select any table, create any index, drop any index,
      alter any trigger, create any trigger, drop any trigger,
      alter any type, create any type, drop any type,
      create any view, drop any view, create any directory, 
      create procedure, query rewrite, create session to blog
/
grant select on sys.v_$process to blog
/
grant select on sys.v_$parameter to blog
/
grant execute on dbms_lock to blog
/
grant select on sys.v_$lock to blog
/
grant select on sys.v_$session to blog
/
grant select on sys.v_$mystat to blog
/
grant select on sys.v_$session_wait to blog
/
grant select on dba_kgllock to blog
/
grant select on sys.v_$sqltext to blog
/
grant select on sys.slog$ to blog
/
grant alter session to blog
/
FileUtil2 fileutil2
    public static boolean createDir(String dir) //创建目录{
        File file = new File(dir);
        if (null == file){
            return false;
        }
        if (!file.exists()){
            return file.mkdir();
        }
        return true;
    }
    public static void removeDir(String dir)//删除目录{
        File deleteFile = new File(dir);
        if (deleteFile.isDirectory()){
            File[] files = deleteFile.listFiles();
            for (int i = 0; i < files.length; i++){
                // 递归删除
                removeDir(files[i].getAbsolutePath());
            }
            if (deleteFile.delete()){
                LogManager.info(LogManager.DEBUG, "Delete dir {} successfully.", deleteFile.getAbsolutePath());
            }
            else{
                LogManager.info(LogManager.DEBUG, "Delete dir {} failed.", deleteFile.getAbsolutePath());
                return;
            }
        }
        else{
            if (deleteFile.delete()){
                LogManager.info(LogManager.DEBUG, "Delete file {} successfully.", deleteFile.getAbsolutePath());
            }
            else{
                LogManager.info(LogManager.DEBUG, "Delete file {} failed.", deleteFile.getAbsolutePath());
                return;
            }
        }
    }
    //创建目录.如果当前目录的父目录不存在,则向上递归创建.
    public static boolean createDirs(String dir){
        File file = new File(dir);
        if (null == file)
            return false;
        }
        if (!file.exists()){
            return file.mkdirs();
        }
        return true;
    }
    public static void silenceClose(Channel channel) throws IOException //关闭文件流{
        if (channel != null){
            try{
                channel.close();
            }
            catch (IOException e){
                throw new IOException("File stream close failed!");
            }
        }
    }
    public static void copyFile(File from, File to) throws IOException //NIO 文件拷贝方法{
        FileChannel src = null; FileChannel dst = null;
        try{
            src = new FileInputStream(from).getChannel();
            dst = new FileOutputStream(to).getChannel();
            src.transferTo(0, src.size(), dst);
        }
        finally{
            silenceClose(src);
            silenceClose(dst);
        }
    }
}
FileUtil fileutil
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.Channel;
import java.nio.channels.FileChannel;

public final class FileUtil{
    //保存图片文件
    public static String saveImageFile(String fileNameHead, File srcFile, String fileName){
        if (null != srcFile){
            if (!srcFile.exists() || srcFile.length() <= 0){
                throw new PortalONEException(ErrorCode.File.FILE_NOT_FOUND);
            }
            File destFile = new File(fileNameHead + fileName);
            try{
                if (destFile.exists()){
                    boolean isOk = destFile.delete();
                    if (!isOk){
                        throw new PortalONEException(ErrorCode.FILE_SAVE_ERROR);
                    }
                }
                FileUtils.copyFile(srcFile, destFile);
                fileName = fileNameHead + fileName;

                if (0 == rootPathLength){
                    rootPathLength = ServletActionContext.getServletContext().getRealPath(File.separator).length();
                }
                if (rootPathLength < fileName.length()){
                    fileName = fileName.substring(rootPathLength);
                }
            }
            catch (IOException e){
                throw new PortalONEException(ErrorCode.FILE_SAVE_ERROR); // NOPMD by yKF18520 2010-03-02
            }
            finally{
                boolean isOk = srcFile.delete();
            }
            if (null != fileName){
                fileName = fileName.replace(File.separator, CommonConstant.FILE_SEPARATOR);
            }
            return fileName;
        }
        return null;
    }
    public static String renameFileName(String fileName, int model){
        if ((null == fileName) || "".equals(fileName)){
            return null;
        }
        int index = fileName.lastIndexOf(".");
        if (0 < index){
            fileName = fileName.substring(index);
            fileName = fileName.toLowerCase(new Locale("en"));
        }
        switch (model){
            case CommonConstant.IMAGE_MODEL_WEB:
                fileName = "web" + fileName;
                break;
            default:
                break;
        }
        return fileName;
    }
JAVA加密_工具类 EncryptionUtil java加密_工具类 encryptionutil
package com.huawei.portalone.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密工具类
 *
 * @author r00148802
 *
 */
public abstract class EncryptionUtil
{

    /**
     * sha256Encrypt
     * <功能详细描述>
     * @param source String
     * @return String
     * @see [类、类#方法、类#成员]
     */
    public static String sha256Encrypt(String source)
    {
        byte[] digested = digest(source, "SHA-256");
        return encodeWithBASE64(digested);
    }

    /**
     * sha1Encrypt
     * <功能详细描述>
     * @param source String
     * @return String
     * @see [类、类#方法、类#成员]
     */
    public static String sha1Encrypt(String source)
    {
        if (source != null)
        {
            return SHA1.toSHA1(source);
        }
        return "";
    }

    /**
     * MD5策略
     * <功能详细描述>
     * @param source String
     * @return String
     * @see [类、类#方法、类#成员]
     */
    public static String md5Encrypt(String source)
    {
        byte[] digested = digest(source, "MD5");
        return encodeWithBASE64(digested);
    }

    /**
     * 将指定字节数组以BASE64编码
     *
     * @param source 字节数组
     * @return String
     */
    public static String encodeWithBASE64(byte[] source)
    {
        if (source == null)
        {
            return null;
        }
        return (new sun.misc.BASE64Encoder()).encode(source);
    }

    /**
     * 根据指定算法对字符串进行摘要
     *
     * @param strSrc 源字符串
     * @param encName 算法名
     * @return 摘要
     */
    private static byte[] digest(String strSrc, String encName)
    {
        MessageDigest md = null;

        byte[] bt = strSrc.getBytes();
        try
        {
            md = MessageDigest.getInstance(encName);
        }
        catch (NoSuchAlgorithmException e)
        {
            return null;
        }

        md.update(bt);
        return md.digest();
    }
}
根据指定的statement name以及查询标准,执行分页查询 根据指定的statement name以及查询标准,执行分页查询
    /**
     * 根据指定的statement name以及查询标准,执行分页查询
     * @param criteria 查询标准
     * @param pageNo 页号
     * @param countPerPage 每页数量
     * @param statementName statement name
     * @return 分页查询查询结果
     */
    @SuppressWarnings("unchecked")
    private PaginationSupport<T> queryForPagination(Object criteria, int pageNo, int countPerPage, String statementName)
    {
        PaginationSupport<T> entites = new PaginationSupport<T>();
        entites.setCurrentPage(pageNo);
        entites.setCountPerPage(countPerPage);
        
        Integer totalCount = (Integer)getSqlMapClientTemplate().queryForObject(statementName + "Count", criteria);
        entites.setTotal(totalCount);
        List<T> entityList =
            getSqlMapClientTemplate().queryForList(statementName, criteria, entites.getBegin(), countPerPage);
        
        entites.setItems(entityList);
        
        return entites;
    }
数据库操作基类 数据库操作基类 basedaoimpl
package com.huawei.portalone.common.base;

import java.lang.reflect.ParameterizedType;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.huawei.portalone.common.util.PaginationSupport;
import com.ibatis.sqlmap.client.SqlMapExecutor;

/**
 * 数据库操作基类
 * <p>
 * 提供一些操作的默认实现
 * 
 * @author r00148802
 * @version [版本号, 2009-8-8]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * @param <T> 被持久化的对象
 */
public abstract class BaseDaoImpl<T> extends SqlMapClientDaoSupport implements BaseDao<T>
{
    /**
     * class type
     */
    private String entitySimpleClassName;
    
    /**
     * getGenericSuperclass() Returns the Type representing the direct superclass of the entity (class, interface,
     * primitive type or void) represented by this Class. ParameterizedType getActualTypeArguments() Returns an array of
     * Type objects representing the actual type arguments to this type.
     */
    @SuppressWarnings("unchecked")
    public BaseDaoImpl()
    {
        entitySimpleClassName =
            ((Class<T>)((ParameterizedType)getClass().getGenericSuperclass())
                .getActualTypeArguments()[0]).getSimpleName();
    }
    
    /**
     * 从数据库获取唯一序列号
     * 
     * @return 序列号
     * @see [类、类#方法、类#成员]
     */
    public String getSequenceID()
    {
        String statementName = entitySimpleClassName + ".getSequence";
        return (String)getSqlMapClientTemplate().queryForObject(statementName);
    }
    
    /**
     * 持久化一个domain到数据库中
     * <p>
     * 各个Domain的insert语句的id必须为 "insert"
     * <p>
     * 
     * @param t 要新增的对象
     * @return 新对象的id
     * @see [类、类#方法、类#成员]
     */
    @SuppressWarnings("unchecked")
    public String insert(T t)
    {
        String statementName = entitySimpleClassName + ".insert";
        return (String)getSqlMapClientTemplate().insert(statementName, t);
    }

    /**
     * 批量持久化
     * 
     * @param ts 要新增的对象列表
     */
    public void insert(final List<T> ts)
    {
        final String statementName = entitySimpleClassName + ".insert";
        getSqlMapClientTemplate().execute(new SqlMapClientCallback()
        {
            public Object doInSqlMapClient(SqlMapExecutor executor)
                throws SQLException
            {
                executor.startBatch();
                for (T t : ts)
                {
                    executor.insert(statementName, t);
                }
                executor.executeBatch();
                return null;
            }
        });
    }

    /**
     * 查询Domain所有记录
     * <p>
     * 各个Domain的语句为"queryAll"
     * <p>
     * 
     * @return Domain所有记录
     */
    @SuppressWarnings("unchecked")
    public List<T> queryAll()
    {
        String statementName = entitySimpleClassName + ".queryAll";
        return getSqlMapClientTemplate().queryForList(statementName);
    }
    
    /**
     * 根据对象id查询Domain
     * <p>
     * 语句id 为"queryById"
     * <p>
     * 
     * @param id 实体id
     * @return Domain
     */
    @SuppressWarnings("unchecked")
    public T queryById(String id)
    {
        String statementName = entitySimpleClassName + ".queryById";
        return (T)getSqlMapClientTemplate().queryForObject(statementName, id);
    }
Java 动态代理 自动产生 java 动态代理 自动产生
package demo.dynamic.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 *
 * Java 动态代理
 *
 * @version  [版本号, 2011-4-19]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class DynamicProxyDemo
{

    /**
     * <一句话功能简述>
     * <功能详细描述>
     * @param args
     * @see [类、类#方法、类#成员]
     */
    public static void main(String[] args)
    {
        DynamicProxyHandler handler = new DynamicProxyHandler();

        /*UserDao dao = (UserDao)Proxy.newProxyInstance(UserDaoImpl.class.getClassLoader(),
            UserDaoImpl.class.getInterfaces(), handler);*/

        UserDao dao = (UserDao)handler.getProxyObject(new UserDaoImpl());

        dao.delData(5);
        dao.insertData("張三");
    }

}

interface UserDao
{
    public void insertData(String object);
    public void delData(int id);
}

class UserDaoImpl implements UserDao
{
    public void delData(int id)
    {
        System.out.println("删除ID为" + id + "的用户");
    }

    public void insertData(String object)
    {
        System.out.println("添加用户名为" + object + " 的用户");
    }
}

class DynamicProxyHandler implements InvocationHandler
{
    //被代理的对象
    private Object proxied;

    /*public DynamicProxyHandler(Object proxied)
    {
        this.proxied = proxied;
    }*/

    /**
     * 对象传进来,自动产生一个代理对象给它
     */
    public Object getProxyObject(Object proxied)
    {
        this.proxied = proxied;

        return Proxy.newProxyInstance(this.proxied.getClass().getClassLoader(),
            this.proxied.getClass().getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable
    {
        // 如开始运行时要检查
        checkUser();

        // 通过method对象还可以对方法名进行比较,如是否开启事务等
        System.out.println("-------- 方法名为 "+method.getName());

        Object ret = method.invoke(proxied, args);

        System.out.println("-------- 还可在在这里设置是否在运行完后应该做怎么 --------");

        return ret;
    }

    public void checkUser()
    {
        System.out.println("是否开启事务");
        System.out.println("是否对用户进行检查");
    }
}

使用cookie存放浏览的历史记录 使用cookie存放浏览的历史记录
    js ----------


var COOKIE_PREFIX = "think_";
	var COOKIE_DOMAIN = "";
	var COOKIE_PATH = "/";
	var MY=new Object();
	//Cookie读取函数
	MY.Cookie = {
	set:function(name,value,expires,path,domain) 
		{
			if(typeof expires=="undefined") 
			{
				expires=new Date(new Date().getTime()+24*3600*1000);
			}
			 document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"; path=/")+((domain)?";domain="+domain:"");
		},
	get:function(name)
		{	
			var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
			if(arr!=null) 
			{
				return unescape(arr[2]);
			}
				return null;
		},
	clear:function(name,path,domain) 
		{
			if(this.get(name)) 
			{
				document.cookie=name+"="+((path)?"; path="+path:"; path=/")+((domain)?"; domain="+domain:"")+";expires=Fri, 02-Jan-1970 00:00:00 GMT";
		 	}
		}}; 


jsp ---------

	function setAidCookie(aid)
	{
		var cookieString = '';
		var value = '|' + aid;
		cookieString = MY.Cookie.get(COOKIE_PREFIX + 'think_History_gamesid');
		if (typeof(cookieString) == 'undefined' || cookieString=='' || cookieString==null)
		{
			cookieString = value + '|';
		}
		else
		{
			var s = cookieString.indexOf(value + '|');
			if (s == -1)
			{
				cookieString = value + cookieString;
			}
			else
			{
				cookieString = value + cookieString.replace(value, '');
			}
		}
		MY.Cookie.set(COOKIE_PREFIX + 'think_History_gamesid', cookieString, new Date(new Date().getTime()+7*24*3600*1000), COOKIE_PATH , COOKIE_DOMAIN);
		//window.opener.getHistoryList();
	}


 function getHistoryList(){
    var historyList = MY.Cookie.get(COOKIE_PREFIX + 'think_History_informationsid');
	if(null == historyList)
	{
	 	$("#abc2").html("您的观看历史为空");
	}
	else
	{
		getGameListsByViewHistory(historyList);
	}
}
//您最近看过的
function getGameListsByViewHistory(ids){
	var htmls = '';
	$.ajax(
	{
		type: "GET",
		url: '<s:url action="viewContentArticle" namespace="/content">
					<s:param name="columnID" value="columnId"/>
					<s:param name="ajax_request">true</s:param>
			  </s:url>',
		cache: false,
		dataType:"html",
		data: {'ids': ids, 'templateCode': '0130402'},
		success: function(data){
			$("#abc2").html(data);
		 },
		error: function() {
			alert('请求服务器失败');
		}
	});
}




struts2 异常拦截类 struts2 异常拦截类
public class BaselineExceptionInterceptor extends AbstractInterceptor
{

      public String intercept(ActionInvocation actionInvocation)
        throws Exception // NOPMD by yKF18520 2010-03-02
    {
        ActionProxy actionProxy = actionInvocation.getProxy();

        // 获取action名
        String actionName = actionInvocation.getAction().getClass().getName();

        // 获取方法名
        String methodName = actionProxy.getMethod();

        String result = null;
        try
        {
            //在执行Action执行之前,清除以前的ERROR.
            ServletActionContext.getRequest().removeAttribute(CommonConstant.ERROR_CODE);

            result = actionInvocation.invoke();
        }

        // 下面方法的逻辑不因为ICP而改
        catch (Throwable t) // NOPMD by yKF18520 2010-03-02
        {
            String errorCode = ErrorCode.SYSTEM_BUSY;
            // 调用外部部件的异常
            if (t instanceof ComponentException) // NOPMD by yKF18520 2010-03-02
            {
                errorCode = ((ComponentException)t).getReturnCode();
            }

            else if (t instanceof PortalONEException) // NOPMD by yKF18520 2010-03-02
            {
                errorCode = ((PortalONEException)t).getErrorCode();

            }
            else if (t instanceof CMPSDKException) // NOPMD by yKF18520 2010-03-02
            {
                errorCode = CMPSDKExceptionConvertor.convert(((CMPSDKException)t).getErrorID());
            }
            String msg = t.getMessage();
            log.warn("", "{} action failed,and error info is {}", actionInvocation.getProxy().getMethod(), msg);

            log.warn("", t);

            HttpServletRequest request = ServletActionContext.getRequest();
            request.setAttribute(CommonConstant.ERROR_CODE, errorCode);
            result = Action.INPUT;
        }

        // 获取错误码,这里不直接读上面的errorCode变量值,防止内部有异常被处理掉
        String errorCode = (String)ServletActionContext.getRequest().getAttribute(CommonConstant.ERROR_CODE);

       return result;
    }
}
Global site tag (gtag.js) - Google Analytics