Ginew.Z 的博客

一切,为了让生活更简单、更自然

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  21 Posts :: 0 Stories :: 14 Comments :: 0 Trackbacks

2006年11月17日 #

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

开发的时候有时需要用link(<a>)来触发一些javascript事件,所以常常可以看到如下的代码:

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

这是一个曾经被多次讨论过的问题,长期以来,我也一直是这样写的。读了 >>a href=”javascript:void(0);” — avoid the void 之后,我认同了作者的意见。下面的写法确实更合理:

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

或者

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

以往大家不使用"#"的问题是,这将导致点击链接时页面跳回页面顶部,但通过 return false 语句将使得浏览器忽略链接的默认动作,从而避免了此问题。

youngpup 更有意思,他在>>How to Create Pop-Up Windows 中言辞激烈的倡导大家永远永远永远不要使用 javascript: 伪协议:

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 无风之雨 阅读(1039) | 评论 (2)编辑 收藏

2006年6月9日 #

     我们打算为用户架设单独的虚拟主机服务器,可以让企业自主上传jsp、htm、php等程序。其中resin用来做jsp的容器。
     由于是用户自主通过FTP上传程序,我们必须控制这些程序可以执行的权限,不能让用户随便浏览硬盘上的文件,但又要能让resin可以正常运行。比如:/data/user_a目录中的程序,只能在/data/user_a目录及其子目录中读写,如果想要访问其他目录,就没有权限。
     通过研究resin的文档以及JAVA的机制,我认为要实现以上构想,可以通过使用java权限管理器来构建一个resin的沙箱来对java的具体操作进行授权。
参考文档:http://www.caucho.com/resin-3.0/security/securitymanager.xtphttp://www.jscud.com/srun/news/viewhtml/3_2005_10/148.htm

     当我认为胜利在望的时候,发现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";
};
     上面的语句,语法上没有问题,但就是不起作用。那个codebase目录下的文件,对本目录没有任何权限。

        resin的官方论坛里面,有人在2001年,针对resin1.2.5就提出了和我一摸一样的疑问(http://www.caucho.com/support/resin-interest/0105/0106.html),作者发现问题是由于resin的classloader是非安全的,因此改了resin原文件后解决了问题(http://www.caucho.com/support/resin-interest/0105/0112.html),但是我看resin3的源代码,里面已经基于java.security.SecureClassLoader,因此应该不是这个原因了。
     以下是我的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对这个目录没有读的权限
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 无风之雨 阅读(666) | 评论 (2)编辑 收藏

2006年5月16日 #

要了解GPL,一般地,您没有必要耐心阅读原版的GPL协议,因为 GPL 无非交待了几个原则:

  • 确保软件自始至终都以开放源代码形式发布,保护开发成果不被窃取用作商业发售。任何一套软件,只要其中使用了受 GPL 协议保护的第三方软件的源程序,并向非开发人员发布时,软件本身也就自动成为受 GPL 保护并且约束的实体。也就是说,此时它必须开放源代码。

  • GPL 大致就是一个左侧版权(Copyleft,或译为“反版权”、“版权属左”、“版权所无”、“版责”等)的体现。你可以去掉所有原作的版权 信息,只要你保持开源,并且随源代码、二进制版附上 GPL 的许可证就行,让后人可以很明确地得知此软件的授权信息。GPL 精髓就是,只要使软件在完整开源 的情况下,尽可能使使用者得到自由发挥的空间,使软件得到更快更好的发展。

  • 无论软件以何种形式发布,都必须同时附上源代码。例如在 Web 上提供下载,就必须在二进制版本(如果有的话)下载的同一个页面,清楚地提供源代码下载的链接。如果以光盘形式发布,就必须同时附上源文件的光盘。

  • 开发或维护遵循 GPL 协议开发的软件的公司或个人,可以对使用者收取一定的服务费用。但还是一句老话——必须无偿提供软件的完整源代码,不得将源代码与服务做捆绑或任何变相捆绑销售。
posted @ 2006-05-16 16:50 无风之雨 阅读(666) | 评论 (0)编辑 收藏

2006年5月14日 #

 

posted @ 2006-05-14 11:28 无风之雨 阅读(263) | 评论 (0)编辑 收藏

2006年4月19日 #

        今天新页面上线,很多同事报告说页面打开到一半,经常跳出无法打开Internet站点的错误,然后页面会跳转到DNS错误的页面。

      notload.jpg
        
        这个问题我以前遇到过,一直没有详细的去深究原因,只是以为是服务器关闭连接太快的原因。今天发现这个问题出的很频繁,服务器方面没有改什么,只是上传了新的页面程序而已,应该不会和服务器有关。在对页面进行分析,并搜索了一下网上,发现原来是js在document还没完全load完的时候就试图改变其值导致。

        因此对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完成后才执行那个操作
posted @ 2006-04-19 18:14 无风之雨 阅读(6892) | 评论 (6)编辑 收藏

2006年4月13日 #

以前如果要使iframe里面的脚本能访问parent的内容,但iframe和parent的二级域名相同,那一般都会在两者都写上document.domain="xxx.com" 以放宽访问权限。

今天发现,如果iframe和parent在同一个三级域名下,比如都是aa.bb.com,那设了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 无风之雨 阅读(9325) | 评论 (3)编辑 收藏

2006年4月11日 #

今天发现,在IE里面,当一个域名包含_的时候,IE不会给这个网站发送COOKIE,真变态。同事调试了半天,才发现还有这个问题
posted @ 2006-04-11 17:54 无风之雨 阅读(267) | 评论 (0)编辑 收藏

    要备份MYSQL,很多人用mysqldump,其实这种方式,导出的文件是最大的,导入的时间是最久的。命令是方便的,但真正发生错误的时候,恢复效率很低。
    我主张,另外找一台比较空闲的机器,来做数据库的备份。这台机器作以下用途:

   它是主数据库带的slave数据库群里面的一台,每天凌晨定时启动同步数据,等追上bin-log并全部执行后,停止同步,并用select * into outfile将数据全部导出成文件,并且在每周的某一天,清除掉主数据库上已经同步好的bin-log,以确保硬盘空间不被log占满。

   为此,我写了3个脚本,分别执行1、启动mysql,追log,然后停止slave;2、导出全部数据库全部文件到文件;3、删除主数据库的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 无风之雨 阅读(648) | 评论 (0)编辑 收藏

一般情况下,Referer和User-Agent同时为空的时候,可以认为是其他网站在批量采集本站数据,我打算deny掉这种请求。不过apache文档里面没有提到有两个环境变量的与操作。最后chinaunix上有大侠回答了我的问题:

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

看字面上,就是如果用两个非的或来代替与
这样,只要两个条件有一个不满足,就log_flag就会变掉,只要它变掉了,就说明不符合我屏蔽的规则。
高手就是高手,为什么非要苛求一定要有“与”呢,两个“非”的“或”,不一样达到要求?

学习了。
posted @ 2006-04-11 12:25 无风之雨 阅读(816) | 评论 (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',建表的时候,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)
// 没有相对应的语法,但一般情况,这个是和substr结合起来用的。
//如果是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),意思就是取第二个-之前的str后(2005-10),再取倒数第一个-之后的内容

oracle的nvl(ss,dd)函数在mysql中怎么实现?
答:ifnull(ss,dd)

posted @ 2006-04-11 12:16 无风之雨 阅读(834) | 评论 (0)编辑 收藏