Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Simple Web snapshot import java.util.Date; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.graphics.GC; import org.e... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data....
Stats
Tomcat GET encoding
edit server.xml :
<Connector
    URIEncoding="UTF-8"
    connectionTimeout="20000"
    port="8080"
    protocol="HTTP/1.1"
    redirectPort="8443"
    />
記得以前只要在 filter 裡設定 request 的 encoding 就可以正常處理
這次怎麼弄 GET 的編碼就是不對...
找到一篇 舊文 說明了此一問題, 還真是一點都沒進步啊...
jQuery serialize form to json
$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
jQuery metadata
$(document).ready(function(){
    var data = $("#message").metadata();
    var i; 
    for(i in data){
        $("#message").append("<div>"+i+"="+data[i]+"</div>");
    }
});
<div id="message" class="mess {firstName:'Bruce',lastName:'Tsai'}"></div>
jQuery validate
利用 css (class屬性), 只能處理預設驗證規則(required, email....)
*Account :
*e-mail :
利用 rules 加入驗證規則與自訂錯誤訊息
Cell Phone :
驗證成功與失敗時的處置
Age1 :
Age2 :
新增移除規則
Test email1:
Test email2:
搭配 Matadata 在 class 屬性中設定驗證規則
Number1 :
自訂驗證規則
Number2 :
Social ID :
驗證規則依存性
address :
(function(){
    $("#form01").validate({
        debug: true  // 除錯模式
    });
    
    $("#form02").validate({
        rules: {
            cellphone: {  // form.name
                required: true,
                digits: true,
                minlength: 5
            }
        },
        messages: {
            cellphone: {  // form.name
                required: "請填寫電話!",
                digits: "請填寫電話號碼!",
                minlength: $.format("至少填入 {0} 個數值")  // 對應驗證的參數
            }
        },
        debug: true
    });
    
    $("#form03").validate({
        submitHandler: function(form){
            alert("Age1 value : " + $("#age1").val());
            form.submit();
            //$(form).ajaxSubmit();
        },
        invalidHandler: function(form, validator){
            var errors = validator.numberOfInvalids();
            alert($.format("錯誤數 : {0}", errors));
        }
    });
    
    $("#form04").validate();
    $("#testemail1").rules("add", {required:true});
    
    $("#form05").validate();
    
    // 新增驗證規則, 作法一
    $.validator.methods.lessThanSquare = function(value, element, param){
        // @value 輸入的值
        // @element 驗證的目標元件
        // @param 設定規則時的參數
        return value * value < param;
    };
    // 新增驗證規則, 作法二
    $.validator.addMethod("testSocialId", function(value, element, param){
        return /\w\d{9}/.test(value);
    }, "身份證號驗證錯誤");
    $("#form06").validate({
        rules: {
            number2: {
                required: true,
                digits: true,
                lessThanSquare: 100
            },
            socialid: {
                required: true,
                testSocialId: true
            }
        },
        messages: {
            number2: {
                lessThanSquare: "數值錯誤"
            }
        }
    });
    
    $("#form07").validate({
        rules: {
            address: {
                required: "#requiredaddresscheck:checked"
            }
        }
    });
})();
Hierarchical Query
Start with connect by prior 階層式查詢用法
SELECT
  s.role_id,
  s.role_name,
  s.role_base_on,
  b.role_name role_base_on_name
FROM m_usr_role s
LEFT JOIN m_usr_role b ON b.role_id = s.role_base_on
ROLE_ID                              ROLE_NAME                                          ROLE_BASE_ON                         ROLE_BASE_ON_NAME                                  
------------------------------------ -------------------------------------------------- ------------------------------------ -------------------------------------------------- 
system.administrator                 系統管理員                                          common.logon.user                    登入帳號                                            
85e9953c-00fd-4a0c-979c-7a41bd3f085a 初學者                                             231570cd-832f-40e3-b198-fb2336245926 訪客                                               
868a17dd-7d21-48a6-b2d5-f9a80313414a 初級專家                                            85e9953c-00fd-4a0c-979c-7a41bd3f085a 初學者                                             
3e9a45b1-82f5-49df-8be6-d67df54760c9 中級專家                                            868a17dd-7d21-48a6-b2d5-f9a80313414a 初級專家                                            
bd6eb9b1-05a3-4059-bc99-90258a7e8d86 高級專家                                            3e9a45b1-82f5-49df-8be6-d67df54760c9 中級專家                                            
886cd029-db55-48ca-8835-d9c2e02fccad 初級顧問                                            bd6eb9b1-05a3-4059-bc99-90258a7e8d86 高級專家                                            
0dec42e1-7de3-4a67-be15-97fbea759771 中級顧問                                            886cd029-db55-48ca-8835-d9c2e02fccad 初級顧問                                            
f5648453-32a5-42c3-8ec1-3b31d0d812fd 高級顧問                                            0dec42e1-7de3-4a67-be15-97fbea759771 中級顧問                                            
231570cd-832f-40e3-b198-fb2336245926 訪客                                                                                                                                       
common.logon.user                    登入帳號                                                                                                                                    

10 個資料列已選取


SELECT
  role_id,
  role_name,
  role_base_on
FROM m_usr_role
START WITH role_name = '高級顧問'
CONNECT BY PRIOR role_base_on = role_id
ROLE_ID                              ROLE_NAME                                          ROLE_BASE_ON                         
------------------------------------ -------------------------------------------------- ------------------------------------ 
f5648453-32a5-42c3-8ec1-3b31d0d812fd 高級顧問                                            0dec42e1-7de3-4a67-be15-97fbea759771 
0dec42e1-7de3-4a67-be15-97fbea759771 中級顧問                                            886cd029-db55-48ca-8835-d9c2e02fccad 
886cd029-db55-48ca-8835-d9c2e02fccad 初級顧問                                            bd6eb9b1-05a3-4059-bc99-90258a7e8d86 
bd6eb9b1-05a3-4059-bc99-90258a7e8d86 高級專家                                            3e9a45b1-82f5-49df-8be6-d67df54760c9 
3e9a45b1-82f5-49df-8be6-d67df54760c9 中級專家                                            868a17dd-7d21-48a6-b2d5-f9a80313414a 
868a17dd-7d21-48a6-b2d5-f9a80313414a 初級專家                                            85e9953c-00fd-4a0c-979c-7a41bd3f085a 
85e9953c-00fd-4a0c-979c-7a41bd3f085a 初學者                                             231570cd-832f-40e3-b198-fb2336245926 
231570cd-832f-40e3-b198-fb2336245926 訪客                                                                                    
8 個資料列已選取

reference : Start with connect by prior 階層式查詢用法
Catch unhandled exception
public class ErrorHandler implements Thread.UncaughtExceptionHandler {

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        System.err.printf("Thread ID : %s%n", t.getId());
        System.err.printf("Message : %s%n", e.getMessage());
    }

    public static void main(String[] args) {
        // register handler
        Thread.setDefaultUncaughtExceptionHandler(new ErrorHandler());

        // throw error
        throw new RuntimeException("My exception!");
    }

}

Know the JVM Series – 1 – The Uncaught Exception Handler

Execute dos command
import java.io.IOException;

public class ExecuteDosCommand {

    public static void main(String[] args) throws IOException, InterruptedException {

        String cmd = null;
        try {
            String s = "command.exe";
            Runtime.getRuntime().exec(s);
            cmd = s;
        } catch (Exception ex) {
            // ex.printStackTrace();
        }
        try {
            String s = "cmd.exe";
            Runtime.getRuntime().exec(s);
            cmd = s;
        } catch (Exception ex) {
            // ex.printStackTrace();
        }

        String s = String.format("%s /C start %s", cmd, "c:\\新增文字文件.txt");
        System.err.println(s);
        Runtime.getRuntime().exec(s);
    }
}

When Runtime.exec() won't