Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... 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... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Tomcat GET encoding
edit server.xml :
  1. <Connector
  2.     URIEncoding="UTF-8"
  3.     connectionTimeout="20000"
  4.     port="8080"
  5.     protocol="HTTP/1.1"
  6.     redirectPort="8443"
  7.     />
記得以前只要在 filter 裡設定 request 的 encoding 就可以正常處理
這次怎麼弄 GET 的編碼就是不對...
找到一篇 舊文 說明了此一問題, 還真是一點都沒進步啊...
jQuery serialize form to json
  1. $.fn.serializeObject = function()
  2. {
  3.     var o = {};
  4.     var a = this.serializeArray();
  5.     $.each(a, function() {
  6.         if (o[this.name]) {
  7.             if (!o[this.name].push) {
  8.                 o[this.name] = [o[this.name]];
  9.             }
  10.             o[this.name].push(this.value || '');
  11.         } else {
  12.             o[this.name] = this.value || '';
  13.         }
  14.     });
  15.     return o;
  16. };
jQuery metadata
  1. $(document).ready(function(){
  2.     var data = $("#message").metadata();
  3.     var i; 
  4.     for(i in data){
  5.         $("#message").append("<div>"+i+"="+data[i]+"</div>");
  6.     }
  7. });
  1. <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 :
  1. (function(){
  2.     $("#form01").validate({
  3.         debug: true  // 除錯模式
  4.     });
  5.     
  6.     $("#form02").validate({
  7.         rules: {
  8.             cellphone: {  // form.name
  9.                 required: true,
  10.                 digits: true,
  11.                 minlength: 5
  12.             }
  13.         },
  14.         messages: {
  15.             cellphone: {  // form.name
  16.                 required: "請填寫電話!",
  17.                 digits: "請填寫電話號碼!",
  18.                 minlength: $.format("至少填入 {0} 個數值")  // 對應驗證的參數
  19.             }
  20.         },
  21.         debug: true
  22.     });
  23.     
  24.     $("#form03").validate({
  25.         submitHandler: function(form){
  26.             alert("Age1 value : " + $("#age1").val());
  27.             form.submit();
  28.             //$(form).ajaxSubmit();
  29.         },
  30.         invalidHandler: function(form, validator){
  31.             var errors = validator.numberOfInvalids();
  32.             alert($.format("錯誤數 : {0}", errors));
  33.         }
  34.     });
  35.     
  36.     $("#form04").validate();
  37.     $("#testemail1").rules("add", {required:true});
  38.     
  39.     $("#form05").validate();
  40.     
  41.     // 新增驗證規則, 作法一
  42.     $.validator.methods.lessThanSquare = function(value, element, param){
  43.         // @value 輸入的值
  44.         // @element 驗證的目標元件
  45.         // @param 設定規則時的參數
  46.         return value * value < param;
  47.     };
  48.     // 新增驗證規則, 作法二
  49.     $.validator.addMethod("testSocialId", function(value, element, param){
  50.         return /\w\d{9}/.test(value);
  51.     }, "身份證號驗證錯誤");
  52.     $("#form06").validate({
  53.         rules: {
  54.             number2: {
  55.                 required: true,
  56.                 digits: true,
  57.                 lessThanSquare: 100
  58.             },
  59.             socialid: {
  60.                 required: true,
  61.                 testSocialId: true
  62.             }
  63.         },
  64.         messages: {
  65.             number2: {
  66.                 lessThanSquare: "數值錯誤"
  67.             }
  68.         }
  69.     });
  70.     
  71.     $("#form07").validate({
  72.         rules: {
  73.             address: {
  74.                 required: "#requiredaddresscheck:checked"
  75.             }
  76.         }
  77.     });
  78. })();
Hierarchical Query
Start with connect by prior 階層式查詢用法
  1. SELECT
  2. s.role_id,
  3. s.role_name,
  4. s.role_base_on,
  5. b.role_name role_base_on_name
  6. FROM m_usr_role s
  7. 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 個資料列已選取


  1. SELECT
  2. role_id,
  3. role_name,
  4. role_base_on
  5. FROM m_usr_role
  6. START WITH role_name = '高級顧問'
  7. 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
  1. public class ErrorHandler implements Thread.UncaughtExceptionHandler {
  2.  
  3.     @Override
  4.     public void uncaughtException(Thread t, Throwable e) {
  5.         System.err.printf("Thread ID : %s%n", t.getId());
  6.         System.err.printf("Message : %s%n", e.getMessage());
  7.     }
  8.  
  9.     public static void main(String[] args) {
  10.         // register handler
  11.         Thread.setDefaultUncaughtExceptionHandler(new ErrorHandler());
  12.  
  13.         // throw error
  14.         throw new RuntimeException("My exception!");
  15.     }
  16.  
  17. }

Know the JVM Series – 1 – The Uncaught Exception Handler

Execute dos command
  1. import java.io.IOException;
  2.  
  3. public class ExecuteDosCommand {
  4.  
  5.     public static void main(String[] args) throws IOException, InterruptedException {
  6.  
  7.         String cmd = null;
  8.         try {
  9.             String s = "command.exe";
  10.             Runtime.getRuntime().exec(s);
  11.             cmd = s;
  12.         } catch (Exception ex) {
  13.             // ex.printStackTrace();
  14.         }
  15.         try {
  16.             String s = "cmd.exe";
  17.             Runtime.getRuntime().exec(s);
  18.             cmd = s;
  19.         } catch (Exception ex) {
  20.             // ex.printStackTrace();
  21.         }
  22.  
  23.         String s = String.format("%s /C start %s", cmd, "c:\\新增文字文件.txt");
  24.         System.err.println(s);
  25.         Runtime.getRuntime().exec(s);
  26.     }
  27. }

When Runtime.exec() won't