愚僧

          贏與輸?shù)牟顒e通常是--不放棄

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            23 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks

          #


          提供一套標(biāo)準(zhǔn), 實現(xiàn)web服務(wù)器之間信息通訊, 接口調(diào)用
          posted @ 2013-02-26 09:44 ywm 閱讀(114) | 評論 (0)編輯 收藏


          語法:
          (select ...)
          union [all] | intersect | minus
          (select ...)

          union              并集,排重, 排序
          union all          并集, 排重
          intersect         交集
          minus             差

          from : http://1632004.blog.163.com/blog/static/29991497201282653334529/
          posted @ 2013-02-26 09:33 ywm 閱讀(509) | 評論 (0)編輯 收藏

          變量
          1. 傳值賦值和傳地址賦值(&)
          - 傳地址比較適合大對象,如數(shù)組和對象類型, 這樣賦值變量時效率更高.
          - 只有變量才可以傳地址賦值

          同一內(nèi)存

          2. 預(yù)定義變量(數(shù)組形式存在)

          $GLOBALS         當(dāng)前腳本中全局范圍內(nèi)的有效的變量
          $_SERVER         有WEB服務(wù)器設(shè)定或當(dāng)前腳本的執(zhí)行環(huán)境相關(guān)的變量
          $_GET               get請求參數(shù)
          $_POST             post請求參數(shù)
          $_COOKIE         客戶端傳遞至服務(wù)器的cookie
          $_FILES            文件上傳變量
          $_ENV              執(zhí)行環(huán)境變量
          $_REQUEST      請求變量
          $_SESSION       會話變量

          3. 變量的范圍
          在include 和 require 引入的文件中有效
          全局范圍的變量在局部范圍內(nèi)(如函數(shù)體內(nèi))無效, 需要使用global(關(guān)鍵字或者globals數(shù)組)去聲明使用全局變量.

          4.靜態(tài)變量
          static $變量名;
          其值會一直保存


          5. 可變變量名
          $vn = "varName";
          $$vn = "varValue";
          echo $varName;
          結(jié)果 : 
          varValue

          6. 確定變量的類型
          gettype()
          array    : is_array()

          float     : is_float()
          integer  : is_int()
          object   : is_object()
          string    : is_string()


          posted @ 2013-02-25 17:45 ywm 閱讀(98) | 評論 (0)編輯 收藏

          有一個已經(jīng)排序的數(shù)組(升序),數(shù)組中可能有正數(shù)、負數(shù)或0,求數(shù)組中元素的絕對值最小的數(shù),要求,不能用順序比較的方法(復(fù)雜度需要小于O(n)),可以使用任何語言實現(xiàn)

          例如,數(shù)組{-20,-13,-4, 6, 77,200} ,絕對值最小的是-4。


          package web;

          import java.util.Arrays;

          /**
           * 有一個已經(jīng)排序的數(shù)組(升序), 數(shù)組中可能有正數(shù)、負數(shù)或0,求數(shù)組中元素的絕對值最小的數(shù), 要求,不能用順序比較的方法 求絕對值最小的數(shù)
           * 
           * 
          @author mayw
           
          */
          public class FindMinValue {

              /**
               * 
               * 
          @param source
               *            原數(shù)組
               * 
          @return 絕對值最小的數(shù)
               * 
          @throws Exception 
               
          */
              public static int[] getMinAbsoluteValue(final int[] source) throws Exception {
                  int[] rvs = null;
                  if(source==null){
                      throw new Exception("非法的原數(shù)組, 對象為null");
                  }
                  int index = binarySearch(source,0);
                  int insertPos = -1 - index;
                  if(index >= 0){
                      return new int[]{0}; // 存在0, 0絕對值最小 
                  }else if(source.length==1){
                      return new int[]{source[0]};
                  }else if(insertPos == source.length){
                      return new int[]{source[source.length - 1]};
                  }else if(insertPos == 0){
                      return new int[]{source[0]};
                  }else if(Math.abs(source[insertPos]) > Math.abs(source[insertPos - 1])){
                      return new int[]{source[insertPos - 1]};
                  }else if(Math.abs(source[insertPos]) == Math.abs(source[insertPos - 1])){
                      return new int[]{source[insertPos - 1],source[insertPos],};
                  }else{
                      return new int[]{source[insertPos]};
                  }
          //        int rv = index >= 0 ? 0
          //                : source[insertPos == source.length ? source.length - 1
          //                        : insertPos];
          //        if(){
          //            
          //        }
          //        return index >= 0 ? 0
          //                : source[insertPos == source.length ? source.length - 1
          //                : insertPos];
              }

              /**
               * 使用二分搜索法來搜索指定的 int 型數(shù)組,以獲得指定的值。
               * 
               * 
          @param source
               *            要查找的目標(biāo)數(shù)組
               * 
          @param target
               *            要查找的數(shù)
               * 
          @return 如果它包含在數(shù)組中,則返回搜索鍵的索引; 否則返回 (-(插入點) - 1)。 插入點
               *         被定義為將鍵插入數(shù)組的那一點:即第一個大于此鍵的元素索引, 如果數(shù)組中的所有元素都小于指定的鍵,則為 a.length。
               *         注意,這保證了當(dāng)且僅當(dāng)此鍵被找到時,返回的值將 >= 0。
               
          */
              public static int binarySearch(final int[] source, int target) {
                  int low = 0;
                  int high = source.length - 1;
                  while(low<=high){
                      int midIdx = (low+high)>>1; // 去中間索引
                      int midVal = source[midIdx]; // 去中間值
                      if(target < midVal){
                          high = midIdx - 1; // 去中間索引的前半部分, 不包含中間索引
                      }else if(target > midVal){
                          low = midIdx + 1; // 去中間索引的后半部分, 不包含中間索引
                      }else{
                          return midIdx; // 返回當(dāng)前索引
                      }
                  }
                  return -low-1;
              }

              public static void main(String[] args) throws Exception {
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{0})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{-1})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{1})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{-4,-2,-1})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{-4,-2,-1,1,2,3,4})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{-4,-2,-1,2,3,4})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{-4,-2,-2,1,3,4})));
                  System.out.println(Arrays.toString(getMinAbsoluteValue(new int[]{1,2,3,4})));
              }

          }


          from : http://www.cnblogs.com/nokiaguy/archive/2013/01/29/2881476.html
          posted @ 2013-02-24 20:51 ywm 閱讀(181) | 評論 (0)編輯 收藏

          /* 參考 : http://www.w3school.com.cn/xmldom/dom_http.asp */
          /*
           * 獲取ajax對象
           
          */
          function getXmlHttpRequest(){
              var xhr = null;
              if(typeof(XMLHttpRequest) != 'undefined'){
                  xhr = new XMLHttpRequest();
              }else{
                  xhr = new ActiveXObject("Microsoft.XMLHttp");
              }
              return xhr;
          }

          /*
           * post方式請求
           
          */
          function post(url, queryString,fn){
              var xhr = getXmlHttpRequest();
              xhr.open('post',url,true);
              xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
              xhr.onreadystatechange=function(){
                  if(xhr.readyState == 4){
                      if(xhr.status == 200){
                          fn.apply(this,[xhr]);
                      }
                  }
              };
              xhr.send(queryString);
          }

          /*
           * get方式請求
           
          */
          function get(url,fn){
              var xhr = getXmlHttpRequest();
              xhr.open('get',url,true);
              xhr.onreadystatechange=function(){
                  if(xhr.readyState == 4){
                      if(xhr.status == 200){
                          fn.apply(this,[xhr]);
                      }
                  }
              };
              xhr.send(null);
          }

           /*
            * 測試
            
          */
          post("ajax","",function(xhr){
              alert(xhr.responseText);
          });
          posted @ 2013-02-22 17:18 ywm 閱讀(106) | 評論 (0)編輯 收藏


          作用:
          監(jiān)聽Container中對象狀態(tài)的變化

          可監(jiān)聽的對象:
          • ServletContext
          • HttpSession
          • ServletRequest
          8個Listener接口和6個Event類:




          from : http://www.aygfsteel.com/i369/articles/236313.html
          posted @ 2013-02-22 11:08 ywm 閱讀(106) | 評論 (0)編輯 收藏

          posted @ 2013-02-22 11:00 ywm 閱讀(113) | 評論 (0)編輯 收藏

          test1.jsp=======================

          <a href ="test.jsp?p=fuck">跳轉(zhuǎn)到test2</a>

          test2.jsp=======================

          <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
          <%
          String path = request.getContextPath();
          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

          out.println("basePath:"+basePath);
          out.println("<br/>");
          out.println("getContextPath:"+request.getContextPath());
          out.println("<br/>");
          out.println("getServletPath:"+request.getServletPath());
          out.println("<br/>");
          out.println("getRequestURI:"+request.getRequestURI());
          out.println("<br/>");
          out.println("getRequestURL:"+request.getRequestURL());
          out.println("<br/>");
          out.println("getRealPath:"+request.getRealPath("/"));
          out.println("<br/>");
          out.println("getServletContext().getRealPath:"+getServletContext().getRealPath("/"));
          out.println("<br/>");
          out.println("getQueryString:"+request.getQueryString());

          %>

          請求路徑:
          http://localhost:8080/test/test.jsp?p=fuck

          顯示結(jié)果:

          basePath:http://localhost:8080/test/

          getContextPath:/test 
          getServletPath:/test.jsp 
          getRequestURI:/test/test.jsp 
          getRequestURL:http://localhost:8080/test/test.jsp 
          getRealPath:D:\Tomcat 6.0\webapps\test\ 
          getServletContext().getRealPath:D:\Tomcat 6.0\webapps\test\ 
          getQueryString:p=fuck

          在一些應(yīng)用中,未登錄用戶請求了必須登錄的資源時,提示用戶登錄,此時要記住用戶訪問的當(dāng)前頁面的URL,當(dāng)他登錄成功后根據(jù)記住的URL跳回用戶最后訪問的頁面:

          String lastAccessUrl = request.getRequestURL() + "?" + request.getQueryString();

          from : http://www.cnblogs.com/JemBai/archive/2010/11/10/1873764.html

          posted @ 2013-02-22 10:56 ywm 閱讀(98) | 評論 (0)編輯 收藏

          1. 語法格式

          • 靜態(tài)包含:<%@ include file="被包含頁面" %>;
          • 動態(tài)包含:<jsp:include page="被包含頁面" />。

           

          2. 區(qū)別

          • 導(dǎo)入路徑 : 靜態(tài)包含是相對于被包含頁面, 動態(tài)包含是相對于包含頁面
          • 動態(tài)包含先編譯成servlet然后包涵(2個servlet) , 靜態(tài)包含先包含后解析成一個servlet
          3.相同點
          • 公用一個request

           

           

          posted @ 2013-02-21 23:10 ywm 閱讀(157) | 評論 (0)編輯 收藏


          全局變量
          1. 方法外
          • var variableName = "variableValue";
          • variableName = "variableValue";
          2. 方法內(nèi)
          • variableName = "variableValue";
          • window.variableName = "variableValue";
          局部變量
          1. 方法內(nèi)
          • var variableName = "variableValue";
          posted @ 2013-02-21 17:09 ywm 閱讀(103) | 評論 (0)編輯 收藏

          僅列出標(biāo)題
          共3頁: 上一頁 1 2 3 下一頁 
          主站蜘蛛池模板: 民县| 呈贡县| 古交市| 新田县| 曲周县| 鱼台县| 左权县| 泾川县| 汉沽区| 忻州市| 诸暨市| 万年县| 宁国市| 海盐县| 吉林市| 射阳县| 沽源县| 彩票| 巩留县| 雷波县| 晋江市| 象山县| 温泉县| 通渭县| 望城县| 庆安县| 宁安市| 周至县| 天台县| 泾源县| 高州市| 石屏县| 长乐市| 清新县| 永登县| 洛浦县| 林西县| 葫芦岛市| 禹州市| 修文县| 罗平县|