Author Archive

基于黑莓平台的MD5密码生成器

前段时间大量密码泄漏的问题闹得挺严重的, 自己也发现我几乎所有网站的注册密码都是相同的. 非常不安全.
如果考虑每个网站使用不同的密码, 对自己来说也是一种负担. 于是就考虑是用md5对自己的密码进行加密.
自己提供一个私钥, 然后输入注册的网站. 之后程序在其中混入数字和符号. 计算md5, 取其中的某几位来生成密码.
这样我只要记住自己的私钥, 那么当我登录weibo的时候, 我的我就在WebSite中写weibo. 这样又好记, 又安全.
我只在自己的黑莓9780上6.0os上测试了, 按道理 96,97应该都能使用.

点击下载: MyMd5Tools - 已下载 25 次

黑莓联通BIS使用Exchange和Google企业套件

2011-10-15, 我在上海开通联通BIS, 想用来收发邮件. 自己之前有域名, 并且注册的Google企业邮箱. 公司用的Exchange 2010, 所有邮件重定向到我自己的邮箱, 这样只收我的私人邮箱就可以了. 问题是回邮件的时候只能用私人邮箱去回复公司邮件, 这点很不好.

但是本周一发现, 我的Google企业邮箱无法收发邮件了, 删掉再添加, 没问题, 但是马上手机就收到一封标题为”Action required. Update settings for xxxxx@xxxx.com”邮件说:

Your xxxxx@xxxx.com email messages are not being delivered to your BlackBerry device. To receive your email messages, turn on the IMAP setting for All Mail in your xxxxx@xxxx.com account.

After your turn on the IMAP setting for All Mail, you must validate your account on your BlackBerry device.

但是无论我修改IMAP还是任何操作, validate 都是没有问题, 但是隔了几秒钟, 又会收到相同的邮件, 登陆 http://chinaunicom.blackberry.com 看到的邮箱也是标红了, 无法收到邮件.

image

这个问题折腾了很久, 还以为和自己混刷有关, 尝试和刷不同版本的4.6和5.0都没有解决. 后来解决方案是让exchange不往google企业邮箱重定向, 而使用blackberry直接收exchange, 用yuchberry收gmail. 也算是一种解决方案, 不过心里还是非常不爽.

在blackberry中添加exchange邮箱直接输入用户名和密码通常就可以了, 也能收发自如, 但是在查看信息(Advanced Settings)的时候, 发现其实走的是imap, 这还Push个P啊. 不行, 继续折腾.

image

无意中发现BlackBerry添加我以前的一个@gmail.com邮箱不会出现之前要求validate问题, 看来只有企业套件有影响, 但是好像联通bis也没提供修改pop3或者imap什么的方法, 这点很头疼. 这样解决, 添加邮箱的时候, 随便写个地址, 一定要是非标准的, 密码也随便写:

image

然后经过漫长的等待…这点要提一下, 联通这个processing页面做的真挫, 一闪一闪的…然后就到了这个页面.

image

点击provide additional settings, 就能自定义server了, 真折腾, 这种用户体验, 活该你用户少…

image

这里就可以设置gmail企业邮箱了, Email server写 imap.gmail.com, User name写完整的邮箱名称

image

之后就解决了, Exchange也是这里设置,

image

之后, 两个邮箱都是正常使用了, 问题解决.

Java循环遍历不定长数组链表

功能描述
一个链表中保存多个不同长度的数组, 根据一个索引值, 能取到对应的元素所在的数组下标

public static int[] calcIndexArr(final List<String[]> list, int index) {
    int listSize;
    if (list == null || (listSize = list.size()) == 0) {
        return new int[0];
    }

    int max = 1;
    for (int i = 0; i < list.size(); i++) {
        max *= list.get(i).length;
    }
    while (index >= max) {
        index -= max;
    }

    int[] indexArr = new int[list.size()];

    for (int i = 0; i < listSize; i++) {
        int b = 1;
        for (int j = i + 1; j < listSize; j++) {
            b *= list.get(j).length;
        }
        int a = index / b;
        indexArr[i] = a;
        index = index - a * b;
    }
    return indexArr;
}

测试方法:

public void testCalcIndexArr() {
    List<String[]> list = new ArrayList<String[]>();
    list.add(new String[2]);
    list.add(new String[4]);
    list.add(new String[1]);
    for (int i = 0; i < 30; i++) {
        int arr[] = RandName.calcIndexArr(list, i);
        assertEquals(3, arr.length);
        System.out.println(arr[0] + "," + arr[1] + "," + arr[2]);
    }
}

测试结果

0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0
1,2,0
1,3,0
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0
1,2,0
1,3,0
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0
1,2,0
1,3,0
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0

PPLive祝大家新年快乐! 3x加油

解决Jsp插入Mysql,设置UTF8依然乱码问题

问题描述:
JSP网页里是charset=UTF-8: 

<%@ page contentType= “text/html; charset=UTF-8 ” language= “java ” import= “java.sql.* ” errorPage= “error.jsp ” %> 

Mysql5里存取的数据库的charset也设成了UTF-8,可是通过JSP网页存取中文还是显示乱码 

解决方案:加个过滤类 

package com.bx.util; 

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; 

public class SetEncodingFilter implements Filter { 

    // ----------------------------------------------------- Instance  Variables 

    /**
     * The default character encoding to set for requests that pass through this
     * filter.
     */
    protected String encoding = null; 

    /**
     * The filter configuration object we are associated with. If this value is
     * null, this filter instance is not currently configured.
     */
    protected FilterConfig filterConfig = null; 

    /**
     * Should a character encoding specified by the client be ignored?
     */
    protected boolean ignore = true; 

    // --------------------------------------------------------- Public Methods 

    /**
     * Take this filter out of service.
     */
    public void destroy() {
        this.encoding = null;
        this.filterConfig = null;
    } 

    /**
     * Select and set (if specified) the character encoding to be used to
     * interpret request parameters for this request.
     *
     * @param request
     * The servlet request we are processing
     * @param result
     * The servlet response we are creating
     * @param chain
     * The filter chain we are processing
     *
     * @exception IOException
     * if an input/output error occurs
     * @exception ServletException
     * if a servlet error occurs
     */
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        // Conditionally select and set the character encoding to be used
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null) {
                request.setCharacterEncoding(encoding);
            }
        } 

        // Pass control on to the next filter
        chain.doFilter(request, response);
    } 

    /**
     * Place this filter into service.
     *
     * @param filterConfig
     * The filter configuration object
     */
    public void init(FilterConfig filterConfig) throws ServletException { 

        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        String value = filterConfig.getInitParameter("ignore");
        if (value == null) {
            this.ignore = true;
        } else if (value.equalsIgnoreCase("true")) {
            this.ignore = true;
        } else if (value.equalsIgnoreCase("yes")) {
           this.ignore = true;
        } else {
           this.ignore = false;
        }
    } 

    // ------------------------------------------------------ Protected Methods 

    /**
     * Select an appropriate character encoding to be used, based on the
     * characteristics of the current request and/or filter initialization
     * parameters. If no character encoding should be set, return
     * <code>null</code>.
     * <p>
     * The default implementation unconditionally returns the value configured
     * by the <strong>encoding</strong> initialization parameter for this
     * filter.
     *
     * @param request
     * The servlet request we are processing
     */
    protected String selectEncoding(ServletRequest request) {
        return (this.encoding);
    }
}

然后在web.xml文件中配置一下就可以了 

<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>com.bx.util.SetEncodingFilter类的路径</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>