Ginew.Z 的博客

          一切,為了讓生活更簡單、更自然

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            21 Posts :: 0 Stories :: 14 Comments :: 0 Trackbacks

          2006年11月17日 #

          href="#" vs. href="javascript:void(0)"

          開發(fā)的時(shí)候有時(shí)需要用link(<a>)來觸發(fā)一些javascript事件,所以常常可以看到如下的代碼:

          <a href="javascript:void(0)" onclick="doSomething();returnfalse;">Link</a>

          這是一個(gè)曾經(jīng)被多次討論過的問題,長期以來,我也一直是這樣寫的。讀了 >>a href=”javascript:void(0);” — avoid the void 之后,我認(rèn)同了作者的意見。下面的寫法確實(shí)更合理:

          <a href="#" onclick="doSomething();returnfalse;">Link</a>

          或者

          <script type="javascript">
          function doSomething() {
            //doSomething
            returnfalse;
          }
          </script>
          <a href="#" onclick="return doSomething();">Link</a>

          以往大家不使用"#"的問題是,這將導(dǎo)致點(diǎn)擊鏈接時(shí)頁面跳回頁面頂部,但通過 return false 語句將使得瀏覽器忽略鏈接的默認(rèn)動作,從而避免了此問題。

          youngpup 更有意思,他在>>How to Create Pop-Up Windows 中言辭激烈的倡導(dǎo)大家永遠(yuǎn)永遠(yuǎn)永遠(yuǎn)不要使用 javascript: 偽協(xié)議:

          Never, ever, ever use the javascript: pseudo-protocol for anything, ever ever ever ever again. Please. Pretty please.

          他的解決方案是:

          <a 
            href="http://google.com/" 
            onclick="window.open(this.href, 'popupwindow', 
            'width=400,height=300,scrollbars,resizable'); 
            returnfalse;">

          這樣的好處就是可以保存到書簽或者收藏夾,可以左鍵單擊,也可以右鍵使用!

          posted @ 2006-11-17 12:15 無風(fēng)之雨 閱讀(1104) | 評論 (2)編輯 收藏

          2006年6月9日 #

          ???? 我們打算為用戶架設(shè)單獨(dú)的虛擬主機(jī)服務(wù)器,可以讓企業(yè)自主上傳jsp、htm、php等程序。其中resin用來做jsp的容器。
          ???? 由于是用戶自主通過FTP上傳程序,我們必須控制這些程序可以執(zhí)行的權(quán)限,不能讓用戶隨便瀏覽硬盤上的文件,但又要能讓resin可以正常運(yùn)行。比如:/data/user_a目錄中的程序,只能在/data/user_a目錄及其子目錄中讀寫,如果想要訪問其他目錄,就沒有權(quán)限。
          ???? 通過研究resin的文檔以及JAVA的機(jī)制,我認(rèn)為要實(shí)現(xiàn)以上構(gòu)想,可以通過使用java權(quán)限管理器來構(gòu)建一個(gè)resin的沙箱來對java的具體操作進(jìn)行授權(quán)。
          參考文檔:http://www.caucho.com/resin-3.0/security/securitymanager.xtphttp://www.jscud.com/srun/news/viewhtml/3_2005_10/148.htm

          ???? 當(dāng)我認(rèn)為勝利在望的時(shí)候,發(fā)現(xiàn)resin好像不支持grant codeBase "file:xxxx 。

          grant codeBase "file:/data/ftpdata/user01.test.com/-" {
          ?permission java.io.FilePermission "/data/ftpdata/user01.test.com/-", "read,write,delete";
          };
          ???? 上面的語句,語法上沒有問題,但就是不起作用。那個(gè)codebase目錄下的文件,對本目錄沒有任何權(quán)限。

          ??????? resin的官方論壇里面,有人在2001年,針對resin1.2.5就提出了和我一摸一樣的疑問(http://www.caucho.com/support/resin-interest/0105/0106.html),作者發(fā)現(xiàn)問題是由于resin的classloader是非安全的,因此改了resin原文件后解決了問題(http://www.caucho.com/support/resin-interest/0105/0112.html),但是我看resin3的源代碼,里面已經(jīng)基于java.security.SecureClassLoader,因此應(yīng)該不是這個(gè)原因了。
          ???? 以下是我的resin.policy文件:

          grant codeBase "file:${java.home}/lib/-" {
          ?permission java.security.AllPermission;
          };

          grant codeBase "file:${java.home}/jre/lib/-" {
          ?permission java.security.AllPermission;
          };

          grant codeBase "file:${resin.home}/lib/-" {
          ?permission java.security.AllPermission;
          };

          grant {
          ?permission java.util.PropertyPermission "*", "read";
          ?permission java.io.SerializablePermission "enableSubstitution";
          ?permission java.lang.reflect.ReflectPermission "suppressAccessChecks";?
          ?permission java.lang.RuntimePermission "accessClassInPackage.*";
          ?permission java.lang.RuntimePermission "getClassLoader";
          ?permission java.lang.RuntimePermission "accessDeclaredMembers";
          ?permission java.lang.RuntimePermission "modifyThreadGroup";
          ?permission java.lang.RuntimePermission "setContextClassLoader";
          ?permission java.lang.RuntimePermission "setIO";
          ?permission java.lang.RuntimePermission "stopThread";
          ?permission java.lang.RuntimePermission "createClassLoader";
          ?permission java.lang.RuntimePermission "getProtectionDomain";
          ?permission java.lang.RuntimePermission "defineClassInPackage";
          ?permission java.security.SecurityPermission "putProviderProperty.SunJCE";
          ?permission java.security.SecurityPermission "insertProvider.SunJCE";
          ?permission java.util.logging.LoggingPermission "control";
          ?permission java.lang.RuntimePermission "getAttribute";
          ?permission java.util.PropertyPermission "jaxp.debug", "read";
          ?permission ognl.OgnlInvokePermission "invoke.*";
          ?permission java.net.SocketPermission "localhost:3306","connect";
          ?permission java.io.FilePermission "${resin.home}/-", "read";
          ?permission java.io.FilePermission "${java.home}/-", "read";
          ?permission java.io.FilePermission "/tmp/-","read,write,delete";
          ?permission java.io.FilePermission "/tmp","read,write,delete";
          ?permission java.io.FilePermission ".","read";
          ?permission java.io.FilePermission "/home/apps/java/jdk/lib/tools.jar","read";
          ?permission java.io.FilePermission "/bin/sh", "read,execute";
          };

          //以下語句沒有任何作用,/data/ftpdata/user01.test.com/下的jsp對這個(gè)目錄沒有讀的權(quán)限
          grant codeBase "file:/data/ftpdata/user01.test.com/-" {
          ?permission java.io.FilePermission "/data/ftpdata/user01.test.com/-", "read,write,delete";
          };

          posted @ 2006-06-09 11:00 無風(fēng)之雨 閱讀(692) | 評論 (2)編輯 收藏

          2006年5月16日 #

          要了解GPL,一般地,您沒有必要耐心閱讀原版的GPL協(xié)議,因?yàn)?GPL 無非交待了幾個(gè)原則:

          • 確保軟件自始至終都以開放源代碼形式發(fā)布,保護(hù)開發(fā)成果不被竊取用作商業(yè)發(fā)售。任何一套軟件,只要其中使用了受 GPL 協(xié)議保護(hù)的第三方軟件的源程序,并向非開發(fā)人員發(fā)布時(shí),軟件本身也就自動成為受 GPL 保護(hù)并且約束的實(shí)體。也就是說,此時(shí)它必須開放源代碼。

          • GPL 大致就是一個(gè)左側(cè)版權(quán)(Copyleft,或譯為“反版權(quán)”、“版權(quán)屬左”、“版權(quán)所無”、“版責(zé)”等)的體現(xiàn)。你可以去掉所有原作的版權(quán) 信息,只要你保持開源,并且隨源代碼、二進(jìn)制版附上 GPL 的許可證就行,讓后人可以很明確地得知此軟件的授權(quán)信息。GPL 精髓就是,只要使軟件在完整開源 的情況下,盡可能使使用者得到自由發(fā)揮的空間,使軟件得到更快更好的發(fā)展。

          • 無論軟件以何種形式發(fā)布,都必須同時(shí)附上源代碼。例如在 Web 上提供下載,就必須在二進(jìn)制版本(如果有的話)下載的同一個(gè)頁面,清楚地提供源代碼下載的鏈接。如果以光盤形式發(fā)布,就必須同時(shí)附上源文件的光盤。

          • 開發(fā)或維護(hù)遵循 GPL 協(xié)議開發(fā)的軟件的公司或個(gè)人,可以對使用者收取一定的服務(wù)費(fèi)用。但還是一句老話——必須無償提供軟件的完整源代碼,不得將源代碼與服務(wù)做捆綁或任何變相捆綁銷售。
          posted @ 2006-05-16 16:50 無風(fēng)之雨 閱讀(686) | 評論 (0)編輯 收藏

          2006年5月14日 #

          ?

          posted @ 2006-05-14 11:28 無風(fēng)之雨 閱讀(282) | 評論 (0)編輯 收藏

          2006年4月19日 #

          ??????? 今天新頁面上線,很多同事報(bào)告說頁面打開到一半,經(jīng)常跳出無法打開Internet站點(diǎn)的錯(cuò)誤,然后頁面會跳轉(zhuǎn)到DNS錯(cuò)誤的頁面。

          ????? notload.jpg
          ????????
          ??????? 這個(gè)問題我以前遇到過,一直沒有詳細(xì)的去深究原因,只是以為是服務(wù)器關(guān)閉連接太快的原因。今天發(fā)現(xiàn)這個(gè)問題出的很頻繁,服務(wù)器方面沒有改什么,只是上傳了新的頁面程序而已,應(yīng)該不會和服務(wù)器有關(guān)。在對頁面進(jìn)行分析,并搜索了一下網(wǎng)上,發(fā)現(xiàn)原來是js在document還沒完全load完的時(shí)候就試圖改變其值導(dǎo)致。

          ??????? 因此對js做如下改變:

          原js:

          ???? window.settimeout("go()",500);
          ???? function go(){
          ??? .......
          ???? }

          改成:

          var go_i=window.setInterval("go()",500);
          function go(){
          ???if(document.readyState=="complete"){
          ????? window.clearInterval(go2_i);
          ??? }
          ????else return;
          ??? ........
          }
          目的就是讓他一定要在document完成后才執(zhí)行那個(gè)操作
          posted @ 2006-04-19 18:14 無風(fēng)之雨 閱讀(6922) | 評論 (6)編輯 收藏

          2006年4月13日 #

          以前如果要使iframe里面的腳本能訪問parent的內(nèi)容,但iframe和parent的二級域名相同,那一般都會在兩者都寫上document.domain="xxx.com" 以放寬訪問權(quán)限。

          今天發(fā)現(xiàn),如果iframe和parent在同一個(gè)三級域名下,比如都是aa.bb.com,那設(shè)了document.domain反而會造成訪問拒絕。

          查了下MSDN,有如下解釋:

          Remarks

          The property initially returns the host name of the server from which the page is served. The property can be assigned the domain suffix to allow sharing of pages across frames. For example, a page in one frame from home.microsoft.com and a page from www.microsoft.com initially would not be able to communicate with each other. However, by setting the domain property of both pages to the suffix "microsoft.com", you ensure that both pages are considered secure and access is available between the pages.

          When you set the domain property, use the domain name determined by the server rather than by the client browser.

          All the pages on different hosts must have the domain property explicitly set to the same value to communicate successfully with each other. For example, the value of the domain property of a page on the host microsoft.com would be "microsoft.com" by default. It might seem logical that if you set the domain property of a page on another host named msdn.microsoft.com to "microsoft.com," that the two pages could communicate with each other. However, this is not the case unless you have also explicitly set the domain property of the page on microsoft.com to "microsoft.com".

          Furthermore, this property cannot be used to allow cross-frame communication among frames with different domain suffixes. For example, a page in one frame from www.microsoft.com and a page in another frame from www.msn.com would not be able to communicate with each other even if the domain property of both pages was set to the suffix "microsoft.com".

          security note Security Alert??Using this property incorrectly can compromise the security of your Web site. Set the domain property only if you must allow cross-domain scripting. Use a value determined on the server. Setting this property to a value determined on the client (like through the location object) could expose your site to attack from another site through Domain Name System (DNS) manipulation. For more information, see Security Considerations: Dynamic HTML.

          For more information on domain security, see About Cross-Frame Scripting and Security.

          posted @ 2006-04-13 11:54 無風(fēng)之雨 閱讀(9357) | 評論 (3)編輯 收藏

          2006年4月11日 #

          今天發(fā)現(xiàn),在IE里面,當(dāng)一個(gè)域名包含_的時(shí)候,IE不會給這個(gè)網(wǎng)站發(fā)送COOKIE,真變態(tài)。同事調(diào)試了半天,才發(fā)現(xiàn)還有這個(gè)問題
          posted @ 2006-04-11 17:54 無風(fēng)之雨 閱讀(277) | 評論 (0)編輯 收藏

          ??? 要備份MYSQL,很多人用mysqldump,其實(shí)這種方式,導(dǎo)出的文件是最大的,導(dǎo)入的時(shí)間是最久的。命令是方便的,但真正發(fā)生錯(cuò)誤的時(shí)候,恢復(fù)效率很低。
          ??? 我主張,另外找一臺比較空閑的機(jī)器,來做數(shù)據(jù)庫的備份。這臺機(jī)器作以下用途:

          ?? 它是主數(shù)據(jù)庫帶的slave數(shù)據(jù)庫群里面的一臺,每天凌晨定時(shí)啟動同步數(shù)據(jù),等追上bin-log并全部執(zhí)行后,停止同步,并用select * into outfile將數(shù)據(jù)全部導(dǎo)出成文件,并且在每周的某一天,清除掉主數(shù)據(jù)庫上已經(jīng)同步好的bin-log,以確保硬盤空間不被log占滿。

          ?? 為此,我寫了3個(gè)腳本,分別執(zhí)行1、啟動mysql,追log,然后停止slave;2、導(dǎo)出全部數(shù)據(jù)庫全部文件到文件;3、刪除主數(shù)據(jù)庫的log

          ---------------------------------------------------------------------------------------
          #!/bin/bash
          #readMasterMysql.sh
          CHECK_MYSQL=0
          /home/mysql/bin/mysqld_safe &
          until [ "$CHECK_MYSQL" = "1" ]
          do
          ? sleep 10
          ? CHECK_MYSQL=`/home/mysql/bin/mysql -uroot -e"show slave status"|awk '{if($14==$21)print "1"}'|tail -n1`
          done
          /home/mysql/bin/mysql -uroot -e"slave stop"
          /home/script/backupMysql.sh
          /home/mysql/bin/mysqladmin shutdown
          WEEK=`date "+%w"`
          if [ $WEEK = "5" ]
          then
          ??? /home/script/purgeLog.sh
          fi

          ------------------------------------------------------------------------------
          #!/bin/bash
          #purgeLog.sh
          LOG_FILE=/home/mysql/data/master.info
          DB_SERVER=`sed -n '4p' $LOG_FILE`
          DB_USER=`sed -n '5p' $LOG_FILE`
          DB_PASS=`sed -n '6p' $LOG_FILE`
          DB_LOGFILE=`sed -n '2p' $LOG_FILE`
          /home/mysql/bin/mysql -h$DB_SERVER -u$DB_USER -p"$DB_PASS" -e"purge master logs to '$DB_LOGFILE'"

          ------------------------------------------------------------------------------
          #!/bin/bash
          #backupMysql.sh
          database=$1
          table=$2
          MYSQL_CLIENT="/home/mysql/bin/mysql -uroot --default-character-set=gbk"
          MYSQL_DUMP="/home/mysql/bin/mysqldump -d -uroot --default-character-set=gbk"
          OUTPUT_PATH=/date/backup
          for databases in `$MYSQL_CLIENT -e "show databases"|grep -v Database`
          do
          if [ "$#" = "0" -o "$database" = "$databases" ] ; then
          ??????? mkdir -p -m777 $OUTPUT_PATH/$databases/
          ??????? $MYSQL_DUMP $databases > $OUTPUT_PATH/$databases/$databases.sql
          ??????? for tables in `$MYSQL_CLIENT -e "show tables" $databases|grep -v Tables_in_`
          ??????? do
          ??????? if [ "$#" = "0" -o "$#" = "1" -o "$table" = "$tables" ] ; then
          ??????????????? mv -f $OUTPUT_PATH/$databases/$tables $OUTPUT_PATH/$databases/$tables.old
          ??????????????? $MYSQL_CLIENT -e "select * into outfile '$OUTPUT_PATH/$databases/$tables' from $tables" $databases
          ??????? fi
          ??????? done
          fi
          done
          posted @ 2006-04-11 12:47 無風(fēng)之雨 閱讀(665) | 評論 (0)編輯 收藏

          一般情況下,Referer和User-Agent同時(shí)為空的時(shí)候,可以認(rèn)為是其他網(wǎng)站在批量采集本站數(shù)據(jù),我打算deny掉這種請求。不過apache文檔里面沒有提到有兩個(gè)環(huán)境變量的與操作。最后chinaunix上有大俠回答了我的問題:

          SetEnv?? log_flag=1
          SetEnvIf Referer !"^$"? log_flag=0
          SetEnvIf user-agent !"^$" log_flag=0
          ...

          看字面上,就是如果用兩個(gè)非的或來代替與
          這樣,只要兩個(gè)條件有一個(gè)不滿足,就log_flag就會變掉,只要它變掉了,就說明不符合我屏蔽的規(guī)則。
          高手就是高手,為什么非要苛求一定要有“與”呢,兩個(gè)“非”的“或”,不一樣達(dá)到要求?

          學(xué)習(xí)了。
          posted @ 2006-04-11 12:25 無風(fēng)之雨 閱讀(842) | 評論 (0)編輯 收藏

          to_date(?, 'YYYY-MM-DD HH24:MI:SS')"
          STR_TO_DATE('2003-15-10 00:00:00','%Y-%m-%d %H:%i:%s');???? //格式不對,會返回NULL

          to_char(create_time,'yyyy-MM-dd')
          DATE_FORMAT(create_time,'%Y-%m-%d')

          sysdate
          now()或者CURRENT_TIMESTAMP?//'1997-12-15 23:50:26',建表的時(shí)候,timestamp類型可以指定default CURRENT_TIMESTAMP

          sysdate - 7?? //7天前
          now()-INTERVAL 7 DAY??

          select * from (select .... where rownum<end) where rownum>start
          limit [start,] length

          substr(productInfor,1,20)
          SUBSTRING('Quadratically',5,6)???? //SUBSTRING(str,pos,len)

          instr(str,substr,pos,index)
          instr(str,substr) 或者 locate(substr,str,pos)
          // 沒有相對應(yīng)的語法,但一般情況,這個(gè)是和substr結(jié)合起來用的。
          //如果是str="2005-10-01"取中間的10這樣的需要,oracle是substr(str,instr(str,'-',1,1)+1,instr(str,'-',1,2)-instr(str,'-',1,1)-1)
          那在mysql里面,可以試試這樣SUBSTRING_INDEX(SUBSTRING_INDEX(str,'-',2),'-',-1),意思就是取第二個(gè)-之前的str后(2005-10),再取倒數(shù)第一個(gè)-之后的內(nèi)容

          oracle的nvl(ss,dd)函數(shù)在mysql中怎么實(shí)現(xiàn)?
          答:ifnull(ss,dd)

          posted @ 2006-04-11 12:16 無風(fēng)之雨 閱讀(853) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 砚山县| 永年县| 都江堰市| 六安市| 房产| 习水县| 教育| 永吉县| 鄂托克旗| 长治市| 仙游县| 蒙城县| 寿光市| 襄城县| 瑞金市| 乌海市| 鸡西市| 博客| 渝北区| 会东县| 东宁县| 英吉沙县| 澄城县| 大悟县| 台北市| 宜宾县| 陵川县| 东阿县| 吴忠市| 凤台县| 桐梓县| 台东县| 周口市| 定西市| 阜新市| 宁安市| 含山县| 青浦区| 鄂伦春自治旗| 天等县| 龙山县|