日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

统计信息

  • 访问量: 12545
  • 日志数: 109
  • 图片数: 1
  • 建立时间: 2007-03-16
  • 更新时间: 2008-10-09

RSS订阅

成长在电信,发展在阿里巴巴。深化性能测试、自动化测试、搜索引擎测试领域,希望能在某个技术领域成为真正的技术大牛。欢迎荐才 http://bbs.51testing.com/viewthread.php?tid=103451&highlight=%B0%A2%C0%EF%B0%CD%B0%CD 。 邮件: jianzhao.liangjz@alibaba-inc.com

我的最新日志

  • javascript 在Firefox 3.0与IE6 脚本下不同表现以及解决方法

    2008-10-09

    1.1       getElementById 区别

    <select name="month">  

    <option>Jan</option>  

    <opton>Feb</option>  

    </select>  

    <select name="month">

    <option>Jan</option>

    <opton>Feb</option>

    </select>

     

    IE中:

    document.getElementById("month") 正确

    document.getElementsByName("month") 正确

     

    Firefox:

    document.getElementById("month") 错误(必须加属性Id)

    document.getElementsByName("month") 正确 

     

    故通用方法编写标准html语法,然后用 document.getElementById.

     

    1.2       FireFox 不支持vbscrīpt

     

     

    1.3       Firefox 定位form

     

    Form 定义   <form name="userlist" id="userlist"  method="post" action="userlist.do">

     

    仅仅IE支持直接访问:

     

    userlist.pageSize.value="20";

            userlist.submit();

     

     

    通用函数

           function goto(p) {

            document.forms["userlist"].page.value=p;

            document.forms["userlist"].pageSize.value="20";

            document.forms["userlist"].submit();

    }

     

     

     

    1.4       事件函数

     

    仅仅 IE支持 document.onclick(){ 这种方式书写。

     

      function document.onclick(){

         with(window.event.srcElement){

        if (tagName != "INPUT" && getAttribute("Author") != "tiannet")

        tiannetHideControl();

         }

       }

    FireFox上提示: missing ( before formal parameters,javascrīpt error

     

     

    1.5       Console关键字

      <scrīpt   type='text/javascrīpt'>  

       

      var   http_request=null;

      alert(console); 

      var   console=null;  

     

    </scrīpt>

     

    firefoxconsole为一个对象

    setting a property that has only a getter

     

     

     

     

    IE 表现为未定义

     

     

    1.6       事件处理

     

    http://www.phpchina.com/12834/viewspace_29308.html

    http://www.javaeye.com/topic/47917

     

     

    如:

     

    function getEvent(){     //同时兼容ieff的写法

            if(document.all)    return window.event;        

            func=getEvent.caller;            

            while(func!=null){    

                var arg0=func.arguments[0];

                if(arg0){

                    if((arg0.constructor==Event || arg0.constructor ==MouseEvent)

                        || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){    

                        return arg0;

                    }

                }

                func=func.caller;

            }

            return null;

    }

     

     

        //任意点击时关闭该控件

       document.onclick=function(){  

         var ōbjevent= getEvent();   //window.event ;//getEvent();

        

        

          if( typeof(objevent.srcElement) == "undefined")

          {

                with(objevent.target)

                {

                             if (tagName != "INPUT" && getAttribute("Author") != "tiannet")

                             {

                                                  tiannetHideControl();

                             }

                }

              }

              else

         {   

               with(objevent.srcElement)

                {

                             if (tagName != "INPUT" && getAttribute("Author") != "tiannet")

                             {

                                                  tiannetHideControl();

                             }

                }      

         }

       }

     

     

     

    1.7       Document.all

    IE 特有:

    document.all.selTianMonth

     

    通用

    document.getElementById('selTianMonth')

     

    1.8       innerText

    http://www.cnlei.org/blog/article.asp?id=425

     

    Firefox下的DOM对象增加innerText属性:

    <scrīpt type="text/javascrīpt">

    var lBrowser = {};

    lBrowser.agt = navigator.userAgent.toLowerCase();

    lBrowser.isW3C = document.getElementById ? true:false;

    lBrowser.isIE = ((lBrowser.agt.indexOf("msie") != -1) && (lBrowser.agt.indexOf("opera") == -1) && (lBrowser.agt.indexOf("omniweb") == -1));

    lBrowser.isNS6 = lBrowser.isW3C && (navigator.appName=="Netscape") ;

    lBrowser.isOpera = lBrowser.agt.indexOf("opera") != -1;

    lBrowser.isGecko = lBrowser.agt.indexOf("gecko") != -1;

    lBrowser.ieTrueBody =function (){

      return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;

    };

    //Firefox下的DOM对象增加innerText属性

    if(lBrowser.isNS6){ //firefox innerText define

      HTMLElement.prototype.__defineGetter__( "innerText",

      function(){

      return this.textContent;

      }

      );

      HTMLElement.prototype.__defineSetter__( "innerText",

      function(sText){

      this.textContent=sText;

      }

      );

    }

    alert(lBrowser.isNS6);

    </scrīpt>

     

    1.9       eval

    创建过程:

     

       for (var i=0;i<5;i++) {

        document.write (' <tr align=center id="trTiannetDay' + i + '" >');

        for (var j=0;j<7;j++){

         document.write('<td align="center" id="tdTiannetDay' + n + '" '+

        'onClick="tiannetDay=this.innerText;tiannetSetValue(true);" '

          +' style="' + s_tiannet_day + '">&nbsp;</td>');

         n ++;

        }

        document.write (' </tr>');

       }

     

     

    IE特有:

      for (var i = 0; i < 35; i++){

     eval("document.all.tdTiannetDay"+i);

          

     

    通用:

         var ōbjname="tdTiannetDay"+ i;

         var da =  eval( document.getElementById(objname)); 

     

           if (typeof(da) == undefined)

               {

                       alert("document.getElementById(tdTiannetDay"+i+"is null");

               }

               else

               {

                   alert(da.tagName);

                      //alert(typeof(da.constructor));

               }

     

    查找到一个区别:http://kongjian.baidu.com/freezesoul/blog/item/f6b7e5cd275752510eb34548.html

     

    javascrīptdom对象和普通对象可以通过判断tagName属性来区别,但是这不是非常好的办法,因为你很难禁止他人在普通对象中定义tagName属性。另外一个比较好的方法是dom对象的constructor属性一般为undefined(同时,显然地,instanceof Object将返回false,这是它们区别其他对象的一个明显特征

     

     

    1.10   execscrīpt

    如: window.execscrīpt("c = Asc(c)", "vbscrīpt");

    仅仅IE支持

     

  • Spring Velocity macro应用与调试

    2008-9-26

    默认情况下,velocity macro文件修改没有被应用服务器检测,必须重启才能生效。

     

     

    Spring  web.xml contextConfigLocation配置包含属性文件mvc-config.xml

     

    <servlet>

    <servlet-name>dispatcherServlet</servlet-name>     

    <servlet-class>  org.springframework.web.servlet.DispatcherServlet        </servlet-class>      

    <init-param>          

    <param-name>contextConfigLocation</param-name>         

    <param-value>

    /WEB-INF/mvc-config.xml

    /WEB-INF/alert-config.xml

    </param-value>   

    </init-param>  

    <load-on-startup>1</load-on-startup>  

     </servlet>

     

     

    mvc-config.xml 部分内容如下:

     

                  <bean id="velocityConfigurer"                           class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">

                  <property name="resourceLoaderPath">

                  <value>WEB-INF/velocity/</value>  

                  </property>

                  <property name="velocityProperties">

                         <props>

                         <prop key="input.encoding">gb2312</prop>

                         <prop key="output.encoding">gb2312</prop>

                         <prop key="contentType">text/html;charset=gb2312</prop>

                         <prop key="file.resource.loader.cache">false</prop>

                         <prop key="file.resource.loader.modificationCheckInterval">1</prop>

                         <prop key="velocimacro.library.autoreload">true</prop>

                         <prop key="velocimacro.library">templates.vm</prop>

                         <prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.SimpleLog4JLogSystem</prop>

                         <prop key="runtime.log">com.ali</prop>

                         <prop key="runtime.log.error.stacktrace">true</prop>

                         <prop key="runtime.log.warn.stacktrace">true</prop>

                         <prop key="runtime.log.info.stacktrace">false</prop>

                         <prop key="runtime.log.invalid.reference">true</prop>

                  </props>

                  </property>

     

           </bean>

          

             <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">

               <property name="suffix"><value>.vm</value></property>

                         <property name="exposeSpringMacroHelpers"><value>true</value></property>

                         <property name="exposeRequestAttributes"><value>true</value></property>

                         <property name="exposeSessionAttributes"><value>true</value></property>

                         <property name="contentType" value="text/html;charset=gb2312" />

                         <property name="dateToolAttribute">

          <value>dateTool</value>

               </property>

            </bean>

     

     

     

    Velocity 文件包括库文件templates.vm都放在WEB-INF/velocity/

    确保velocity文件被修改都立即重新扫描,关键的参数:

    <prop key="file.resource.loader.cache">false</prop>

                         <prop key="file.resource.loader.modificationCheckInterval">1</prop>

                         <prop key="velocimacro.library.autoreload">true</prop>

     

     

    index.vm上通过:

    #parse("templates.vm") 引入velocity 模版。

  • Spring+mysql+velocity 中文问题解决方法

    2008-9-23

    碰到中文问题主要有几类:

    1)      confluencemysql数据库导出的 UTF-8数据

    2)      http get/post 请求中汉字

    3)      ajax xmlhttprequest传递的汉字

    4)      mysql 环境设置

    5)      spring /velocity /jboss环境的中文配置

     

    成功的文件配置关键内容如下:

    1.1       spring2应用Web.xml 配置

     

    <filter>

                  <filter-name>encodingFilter</filter-name>

                  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

                  <init-param>

                         <param-name>encoding</param-name>

                         <param-value>GB2312</param-value>

                  </init-param>

                 

                  <init-param>

                <param-name>forceEncoding</param-name>

                <param-value>true</param-value>

        </init-param>

     

           </filter>

     

     

    1.2       Ibatis  sqlmap-config.xml

     

    <?xml version="1.0"  encoding="UTF-8" ?>

     

     

    1.3       ibatis jdbc配置:

    jdbc.driverClassName=com.mysql.jdbc.Driver

    jdbc.url=jdbc:mysql://127.0.0.1:3306/scmproj?useUnicode=true&characterEncoding=UTF-8

     

     

     

     

    1.4       spring mvc:

     

           <bean id="velocityConfigurer"                           class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">

                  <property name="resourceLoaderPath">

                  <value>WEB-INF/velocity/</value>  

                  </property>

                  <property name="velocityProperties">

                         <props>

                         <prop key="input.encoding">GB2312</prop>

                         <prop key="output.encoding">GB2312</prop>

                         <prop key="contentType">text/html;charset=GB2312</prop>

                         <prop key="file.resource.loader.cache">false</prop>

                         <prop key="file.resource.loader.modificationCheckInterval">1</prop>

                         <prop key="velocimacro.library.autoreload">true</prop>

                         <prop key="velocimacro.library">templates.vm</prop>

                         <prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.SimpleLog4JLogSystem</prop>

                         <prop key="runtime.log">com.ali</prop>

                         <prop key="runtime.log.error.stacktrace">true</prop>

                         <prop key="runtime.log.warn.stacktrace">true</prop>

                         <prop key="runtime.log.info.stacktrace">false</prop>

                         <prop key="runtime.log.invalid.reference">true</prop>                        

                  </props>

                  </property>

     

           </bean>

          

             <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">

               <property name="suffix"><value>.vm</value></property>

                         <property name="exposeSpringMacroHelpers"><value>true</value></property>

                         <property name="exposeRequestAttributes"><value>true</value></property>

                         <property name="exposeSessionAttributes"><value>true</value></property>

                         <property name="contentType" value="text/html;charset=UTF-8" />

                         <property name="dateToolAttribute">

          <value>dateTool</value>

               </property>

            </bean>

          

     

    由于页面上文字是汉字,但数据库为utf-8VelocityViewResolvercontentType必须为UTF-8 ,否则部分复杂汉字无法正常显示。如璟。

     </