caoyinghui

          模式窗口的使用

          <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script>  //補(bǔ)充完成下邊的函數(shù),打開新的一個(gè)模式窗口  function openShowModalDialog(){      var obj = window;      var params  = new Array("aaaa",obj);

            var returnValue = window.showModalDialog("DEMO04_01.html",params);

            document.getElementById("showContentDiv").innerHTML=returnValue;

           }

            </script>

          </head>

          <body>

          <h1>模式窗口的使用:</h1> <h3>補(bǔ)充完成openShowModalDialog函數(shù),打開新的一個(gè)模式窗口</h3> <button onclick="openShowModalDialog();">打開新的模式窗口</button> <br> <hr> <div id="showContentDiv">

          </div>   </body> </html>

          DEM004-01.html

          <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head>

          <script>

           //補(bǔ)充完成函數(shù),將文本框returnValue的值設(shè)置為父窗口返回值,并關(guān)閉本窗口  function closeShowModalDialog(){        //獲得模式窗體的參數(shù)。         var p = window.dialogArguments;          window.returnValue=document.getElementById("returnValue").value;      //設(shè)置父窗體的返回值 p[1] 事實(shí)上是拿到了父窗體的引用      p[1].returnValue=document.getElementById("returnValue").value;

               window.close();  }   </script>

          </head>

          <body>

          <h1>模式窗口的使用:</h1> <h3>補(bǔ)充完成closeShowModalDialog函數(shù),將文本框returnValue的值設(shè)置為父窗口返回值,并關(guān)閉本窗口</h3> <button onclick="closeShowModalDialog();">設(shè)置返回值,并關(guān)閉窗口</button> <hr> 窗口的返回值 <input type="text" id="returnValue" value="在這里設(shè)置返回值">   </body> </html>

          作者:caoyinghui1986 發(fā)表于2008-6-15 12:27:00 原文鏈接
          閱讀:365 評(píng)論:0 查看評(píng)論

          posted @ 2008-06-15 04:27 shine_panda 閱讀(435) | 評(píng)論 (0)編輯 收藏

          框架中取值問(wèn)題

          DEM003.html

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
          
          <html xmlns="http://www.w3.org/1999/xhtml">
          
          <head>
          
          </head>
          
          
          
          <frameset rows="70,*" cols="*" framespacing="0" frameborder="yes" style="border:0px">
          
            <frame src="DEMO03_bar.html" name="bar" scrolling="No" noresize="noresize" id="bar"arginwidth="0" marginheight="0" />
          
            <frameset cols="150,*" frameborder="yes" border="1" framespacing="0">
          
              <frame src="DEMO03_menu.html" name="menu" scrolling="No" noresize="noresize" id="menu" marginwidth="0" marginheight="0" />
          
              <frame src="DEMO03_main.html" name="mainFrame" id="main" marginwidth="0" marginheight="0" />
          
            </frameset>
          
          </frameset>
          
          <noframes><body>
          
          </body>
          
          </noframes></html>
          
          

          DEM003_bar.html

          <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script>  //補(bǔ)充完成此函數(shù),用于刷新Menu窗體的頁(yè)面  function flushMenuFrame(){      //top表示頂級(jí)窗口 的 window對(duì)象   window.top.menu.location.href="DEMO03_menu.html";  }  

           //補(bǔ)充完成此函數(shù),將barText文本框的值寫入到Main窗口的mainText中去。  function writeValueToMainFrame(){      //parent表示 但前窗口的 上級(jí)窗口的 window對(duì)象        window.parent.mainFrame.document.getElementById("mainText").value=document.getElementById("barText").value;    } </script>

          </head>

          <body> <center>BAR頁(yè)面</center> <button onclick="flushMenuFrame();">刷新框架Menu窗口的頁(yè)面</button> Bar頁(yè)面的文本框:<input type="text" id="barText" value="Bar頁(yè)面的值1"><button onclick="writeValueToMainFrame();">向Main窗口寫值</button> </body> </html>

          DEMO003_main.html

          <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> </head>

          <body> <center>Main窗體</center> <br><br> Main窗體中的文本框 <input type="text" id="mainText" value="Main頁(yè)面的值2"> </body> </html>

           

          作者:caoyinghui1986 發(fā)表于2008-6-15 12:24:00 原文鏈接
          閱讀:267 評(píng)論:0 查看評(píng)論

          posted @ 2008-06-15 04:24 shine_panda 閱讀(78) | 評(píng)論 (0)編輯 收藏

          Hibernate向數(shù)據(jù)庫(kù)插入圖片

          實(shí)現(xiàn)功能是 用戶本地瀏覽一個(gè)圖片后(本來(lái)要用上傳 為簡(jiǎn)單起見(jiàn)就制作本地測(cè)試) 功過(guò)Hibernate中向數(shù)據(jù)庫(kù)插入圖片 并在另一個(gè)頁(yè)面把這個(gè)圖片顯示出來(lái) 

          index.jsp

          <body>
            <form  name="frm" action="imgServlet" method="post">
              <input type="file" name="path"/>
             
              <input type="submit" value="提交">
              </form>
            </body>

          一個(gè)簡(jiǎn)單的表單用于瀏覽圖片

          Img.java

          public class Img  implements java.io.Serializable {


              // Fields   

               private Integer id;
               private byte[] img;

          ......

          }

          Img.hbm.xml

          <hibernate-mapping>
              <class name="hib.Img" table="img" schema="dbo" >
                  <id name="id" type="java.lang.Integer">
                      <column name="id" />
                      <generator class="identity" />
                  </id>
                  <property name="img" type="binary">
                      <column name="img" not-null="true" />
                  </property>
              </class>
          </hibernate-mapping>

           

          servlet中的處理方式   (web.xml 中 <url-pattern>/imgServlet</url-pattern> 對(duì)這個(gè)servlet的配置)

          public void doPostt(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {

            response.setContentType("text/html");
            //PrintWriter out2 = response.getWriter();
            //servlet 中 out 對(duì)象只可取一次.
            
            //如果要用與輸出二進(jìn)制數(shù)據(jù) . 就必須用 OutputStream 對(duì)象.
            
            OutputStream out = response.getOutputStream();
            
            request.setCharacterEncoding("UTF-8");
            String path = request.getParameter("path");
            
            java.io.File file = new File(path);
            
            InputStream inputStream = new FileInputStream(file);
            byte[] buff= new byte[(int) file.length()];
            inputStream.read(buff, 0, (int) file.length());
            
            Img img = new Img();
            img.setImg(buff);
            
            
            Session session  = HibernateSessionFactory.getSession();
            session.save(img);
            session.beginTransaction().commit();
            String realPath = request.getSession().getServletContext().getRealPath("/");
            System.out.println("realPath"+realPath);
            
            System.out.println("path:"+path);
            
           
            System.out.println("插入成功!!!");
            
            try {
            
             //將圖片寫入到輸出流中
             out.write(img.getImg());
            } catch (Exception e) {
             e.printStackTrace();
            }

            //request.getRequestDispatcher("show.jsp").forward(request, response);
            response.sendRedirect("show.jsp");
            out.flush();
            out.close();
            
           }

           

          show.jsp

          <body>
             <img src="imgServlet"/>
            </body>

           

          通過(guò)提交就可以在 show.jsp看到用戶提交的圖片并且改圖片保存到了數(shù)據(jù)庫(kù)

          作者:caoyinghui1986 發(fā)表于2008-6-6 14:52:00 原文鏈接
          閱讀:475 評(píng)論:1 查看評(píng)論

          posted @ 2008-06-06 06:52 shine_panda 閱讀(233) | 評(píng)論 (0)編輯 收藏

          SSH和Tomcate中連接池的配置方式

          每次在CSDN回貼的時(shí)候都會(huì)遇到好多關(guān)于連接池的貼。自己在測(cè)試的時(shí)候也發(fā)現(xiàn)這個(gè)東西,有時(shí)候確實(shí)比較麻煩。干脆就花了一點(diǎn)時(shí)間把他們總結(jié)了
          一下.

          我機(jī)器的環(huán)境是 Eclipse3.2 + tomcate5.5+ JDK1.5 +sqlserver2000
          測(cè)試前 首先要確保 sql2000 打了spk3,spk4補(bǔ)丁包。


          struts中c3p0 連接池的配置。
          <data-sources >
             <data-source key="ds" type="com.mchange.v2.c3p0.ComboPooledDataSource">
                <set-property property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
                <set-property property="url" value="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs" />
                <set-property property="maxCount" value="10"/>
                <set-property property="minCount" value="1"/>
                <set-property property="username" value="sa" />
                <set-property property="password" value="" />  
          </data-source>


          Action中獲得這個(gè)連接的方式。
          DataSource ds =  this.getDataSource(request,"ds");


          struts中dbcp 連接池的配置
              <data-source key="dsDBCP" type="org.apache.commons.dbcp.BasicDataSource">
                <set-property property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
                <set-property property="url" value="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs" />
                <set-property property="maxCount" value="10"/>
                <set-property property="minCount" value="1"/>
                <set-property property="username" value="sa" />
                <set-property property="password" value="" />  
             </data-source>


          使用 dbcp 連接池 時(shí)除了要注意 導(dǎo)入必要的 3個(gè)連接池驅(qū)動(dòng)包外 還要引入sql的三個(gè)驅(qū)動(dòng)包。

           

          -------------------------------------------------------------------------------------------------------------------------------
          Spring中dbcp 連接池的配置

          jdbc.properties


          jdbc.driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver
          jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs
          jdbc.username=sa
          jdbc.password=


          jdbc.properties 文件來(lái)定義連接信息。

          在 dbcpPoolBean.xml文件中的bean配置。

          <bean id="aa" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <!-- 對(duì)與單個(gè)文件 這里可以直接用 location屬性 然后給一個(gè) value單值 原因是因?yàn)樵谄?父類的實(shí)現(xiàn)中
             PropertiesLoaderSupport 有個(gè) setLocation方法.
              public void setLocation(Resource location) {
                  this.locations = new Resource[] {location};
                 }
               
                public void setLocations(Resource[] locations) {
               this.locations = locations;
                    }
                 所以單個(gè)文件可以簡(jiǎn)單的用 location對(duì)應(yīng)一個(gè) 值(value)
               
                -->
               
               
           
            <property name="locations">
             <list>
              <value>classpath:jdbc.properties</value>
             </list>
            </property>
           </bean>
           
           <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="username" value="${jdbc.username}"/>
           </bean>

           

          客戶段可以通過(guò)
            ApplicationContext ctx = new ClassPathXmlApplicationContext("dbcpPoolBean.xml");
            
            DataSource ds =  (org.apache.commons.dbcp.BasicDataSource )ctx.getBean("dataSource");
          來(lái)獲得數(shù)據(jù)源。當(dāng)然在web開發(fā)中可以通過(guò)容器自動(dòng)注入。

           

          ----------------------------------------------------------------------------------------------------------------------------

          Tocmate5.5中配置數(shù)據(jù)源:


          自己在配置這個(gè)東西的時(shí)候搞了好久 ,最后還是求助 CSDN解決的
          貼子http://topic.csdn.net/u/20080605/20/7fdd0eee-9c43-428a-8b82-5db9a1968151.html
          總結(jié)下幾個(gè)需要注意的地方:
          1,首先在 tomcate 的server.xml文件中正確配置
          2,要將相關(guān)的驅(qū)動(dòng)包(sql的和連接池的)copy到 C:/Tomcat 5.5/common/lib(我的tomcate在c盤)

          server.xml中的配置信息:

           <Context path="/testPool"
            docBase="F:/Exercise/Newer/tomcatePool/WebRoot"
            debug="5"     
              reloadable="true"
              crossContext="true">
             
             <Resource name="jdbc/userDB"
                auth="Container"   
                       type="javax.sql.DataSource"
                factory="org.apache.commons.dbcp.BasicDataSourceFactory"
                       username="sa"
                       password=""        
                       driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"  
                       url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"   
                       maxActive="100" 
                       maxIdle="1000"
                        maxWait="5000"/>   
          </Context>

          讀取連接池的方法:
                try{
               
                 Context ctx = new InitialContext();
                 DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/userDB");
                 //可以獲得 ds
                 System.out.println(ds);
                
                 Connection con = ds.getConnection();
                
                 System.out.println("我的到了連接拉:"+con);
                 //out.println( ds.getConnection());
                 }catch(Exception ex){
                
                   ex.printStackTrace();
                   
                 }

          通過(guò)這兩步配置后你就可以用 http://localhost:8080/testPool/來(lái)訪問(wèn) 你的資源 testPool 是你在 <Context path="/testPool"/> 中path的值匹配


          如果你吧你的項(xiàng)目部署到tomcate還是不能獲得連接。 這是你要在 C:/Tomcat 5.5/conf/Catalina/localhost 下新建一個(gè)xml 文件 (tomcatePool.xml)
          tomcatePool 是你的當(dāng)前項(xiàng)目的名字。
          這樣就可以通過(guò) http://localhost:8080/tomcatePool/ 來(lái)訪問(wèn)你的資源了。這時(shí) server.xml文件中就可以不配置。
          tomcatePool.xml
           <Context path=""
            docBase=""
            debug="5"     
              reloadable="true"
              crossContext="true">
             
             <Resource name="jdbc/userDB"
              auth="Container"   
                     type="javax.sql.DataSource"
                     factory="org.apache.commons.dbcp.BasicDataSourceFactory"
                     username="sa"
                     password=""        
                     driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"  
                     url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"   
                     maxActive="100" 
                     maxIdle="1000"
                     maxWait="5000"/>   
          </Context>

          注意path和docBase 因?yàn)槭峭ㄟ^(guò)項(xiàng)目名來(lái)訪問(wèn)的所以這兩個(gè)值沒(méi)有意義。


          ------------------------------------------------------------------------------------------------------------------------------
          hibernate 中獲得容器(tomcate)中的數(shù)據(jù)源。

          只要加 一個(gè)配置。
          hibernate.cfg.xml文件

          <property name="connection.datasource">java:comp/env/jdbc/userDB</property>

          有了這個(gè)后
          <!-- <property name="connection.username">sa</property>-->
          <!-- <property name="connection.url">-->
          <!--  jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=temp-->
          <!-- </property>-->
          <!-- <property name="myeclipse.connection.profile">sql2000</property>-->
          <!-- <property name="connection.driver_class">-->
          <!--  com.microsoft.jdbc.sqlserver.SQLServerDriver  -->
          <!-- </property>-->

          這些就可以注釋掉呢。
          另外測(cè)試中發(fā)現(xiàn) .hbm.xml 文件中的 catalog="temp" 屬性可以覆蓋 數(shù)據(jù)源中
           url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"   這里配置的數(shù)據(jù)庫(kù)名稱。
           

          ****************************************************************************************************

          目前就只做了這么多 以后遇到了新的再來(lái)補(bǔ)充.

           

           

           

           

          作者:caoyinghui1986 發(fā)表于2008-6-6 14:28:00 原文鏈接
          閱讀:1290 評(píng)論:3 查看評(píng)論

          posted @ 2008-06-06 06:28 shine_panda 閱讀(230) | 評(píng)論 (0)編輯 收藏

          Hibernate映射類型對(duì)照表

          Hibernate映射類型對(duì)照表
          java類型  Hibernate映射類型  SQL類型
          java.math.BigDecimal big_decimal numeric
          byte[] binary varbinary(blob)
          boolean(java.lang.Boolean) boolean bit
          byte(java.lang.Byte) byte  tinyint
          java.util.Calendar calendar timestamp
          java.sql.Clob clob clob
          java.util.Date 或java.sql.Date date date
          double(java.lang.Double) double double
          float(java.lang.Float) float float
          int (java.lang.Integer) integer integer
          java.util.Local local varchar
          long(java.lang.Long) long bigint
          java.io.Serializable的某個(gè)實(shí)例 serializable varbinary(或blob)
          java.lang.String string varchar
          java.lang.String text clob
          java.util.Date 或 java.sql.Timestamp time timestamp

          從書上把這個(gè)表抄下來(lái)方便以后查閱.

          考慮到  操作 blob 的字段太復(fù)雜 一個(gè)變換的技巧是 . 實(shí)體類用 byte[] 類型 ,  hibernate 類型用 binary ,數(shù)據(jù)庫(kù)還是用 blob .這樣 可以簡(jiǎn)化一些操作.

          作者:caoyinghui1986 發(fā)表于2008-6-4 20:56:00 原文鏈接
          閱讀:1161 評(píng)論:0 查看評(píng)論

          posted @ 2008-06-04 12:56 shine_panda 閱讀(125) | 評(píng)論 (0)編輯 收藏

          Spring 和struts 整合的三種方式

          Spring 和 struts 整合的三種方式。

          1,使用Spring 的 ActionSupport
          2, 使用Spring 的 DelegatingRequestProcessor 類。
          3,全權(quán)委托。

          無(wú)論用那種方法來(lái)整合第一步就是要為struts來(lái)裝載spring的應(yīng)用環(huán)境。 就是在 struts 中加入一個(gè)插件。
          struts-config.xml中

           <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
            <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
           </plug-in>


          spring 的配置文件被作為參數(shù)配置進(jìn)來(lái)。這樣可以省略對(duì)web.xml 文件中的配置。確保你的applicationContext.xml 在WEB-INF目錄下面

          1,使用Spring的ActionSupport .
          Spring 的ActionSupport 繼承至 org.apache.struts.action.Action
          ActionSupport的子類可以或得 WebApplicationContext類型的全局變量。通過(guò)getWebApplicationContext()可以獲得這個(gè)變量。

          這是一個(gè) servlet 的代碼:
          public class LoginAction extends org.springframework.web.struts.ActionSupport {
           
           public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response) {
            LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
                          //獲得  WebApplicationContext  對(duì)象             
            WebApplicationContext ctx = this.getWebApplicationContext();
            
            LoginDao dao = (LoginDao) ctx.getBean("loginDao");
            User u = new User();
            
            u.setName(loginForm.getName());
            u.setPwd(loginForm.getPwd());
            
            
            if(dao.checkLogin(u)){
             return mapping.findForward("success");
            }else{
             return  mapping.findForward("error");
            }
            
           }
          }

          applicationContext.xml 中的配置
          <beans>
           <bean id="loginDao" class="com.cao.dao.LoginDao"/>
          </beans>

          這中配置方式同直接在web.xml文件配置差別不大。注意:Action繼承自 org.springframework.web.struts.ActionSupport 使得struts和spring耦合在一起。
          但實(shí)現(xiàn)了表示層和業(yè)務(wù)邏輯層的解耦(LoginDao dao = (LoginDao) ctx.getBean("loginDao"))。


          2,使用Spring 的 DelegatingRequestProcessor 類
          DelegatingRequestProcessor  繼承自 org.apache.struts.action.RequestProcessor 并覆蓋了里面的方法。
          sturts-config.xml  中  <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> 通過(guò) <controller >來(lái)替代
                                  org.apache.struts.action.RequestProcessor 的請(qǐng)求處理。

          public class LoginAction extends Action {
           //利用spring來(lái)注入這個(gè)對(duì)象。
           private LoginDao dao ;
           
           public void setDao(LoginDao dao) {
            System.out.println("執(zhí)行注入");
            this.dao = dao;
           }

           public LoginDao getDao() {
            return dao;
           }

           public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response) {
            LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
            //這樣一改這行代碼似乎沒(méi)有必要了。
            //WebApplicationContext ctx = this.getWebApplicationContext();
            //LoginDao dao = (LoginDao) ctx.getBean("loginDao");
           
            User u = new User();
            
            u.setName(loginForm.getName());
            u.setPwd(loginForm.getPwd());
            
            //直接用dao來(lái)調(diào)用spring會(huì)將這個(gè)對(duì)象實(shí)例化。
            if(dao.checkLogin(u)){
             return mapping.findForward("success");
            }else{
             return  mapping.findForward("error");
            }
            
           }
          }
          這里的。
          LoginAction extends Action 說(shuō)明 struts 每有和spring 耦合。
          看一下
          applicationContext.xml 中的配置。
          <beans>
           <bean id="loginDao" class="com.cao.dao.LoginDao"/>
           
           <bean name="/login" class="com.cao.struts.action.LoginAction">
            <property name="dao">
             <ref local="loginDao"/>
            </property>
           </bean>
          </beans>

          這里 name="/login" 與struts 中的path匹配
              class="com.cao.struts.action.LoginAction" 與struts 中的type匹配

          還要為 LoginAction 提供必要的setXXX方法。 獲得ApplicationCotext和依賴注入的工作都在DelegatingRequestProcessor中完成。


          3,全權(quán)委托:
          Action 的創(chuàng)建和對(duì)象的依賴注入全部由IOC容器來(lái)完成。 使用Spring的DelegatingAcionProxy來(lái)幫助實(shí)現(xiàn)代理的工作
          org.springframework.web.struts.DelegatingActiongProxy繼承于org.apache.struts.action.Action .


          全權(quán)委托的配置方式同 方式 2 類似 (applcationContext.xml文件的配置和 Action類的實(shí)現(xiàn)方式相同)。
          <struts-config>
            <data-sources />
            <form-beans >
              <form-bean name="loginForm" type="com.cao.struts.form.LoginForm" />

            </form-beans>

            <global-exceptions />
            <global-forwards />
           <action-mappings >
              <!-- type指向的是spring 的代理類 -->
              <action
                attribute="loginForm"
                input="login.jsp"
                name="loginForm"
                path="/login"
                scope="request"

                type="org.springframework.web.struts.DelegatingActionProxy" >
               
                <forward name="success" path="/ok.jsp" />
                <forward name="error" path="/error.jsp" />
              </action>
           
           </action-mappings>
           
            
            <message-resources parameter="com.cao.struts.ApplicationResources" />

           <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
            <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
           </plug-in>

          </struts-config>
          不同之處
          1, <action>中 type指向的是spring 的代理類

          2, 去掉struts-config.xml中 <controller >

           

          三種整和方式中我們優(yōu)先選用 全權(quán)委托的方式。
          理由:
          1,第一種使得過(guò)多的耦合了Spring和Action .
          2,RequestProcessor類已經(jīng)被代理 如果要再實(shí)現(xiàn)自己的實(shí)現(xiàn)方式(如:編碼處理)怕有點(diǎn)麻煩。

          總結(jié)一下:
          整合工作中的步驟:
          1,修改struts-config.xml  
          2, 配置applicationContext.xml
          3, 為Action添加get/set方法 來(lái)獲得依賴注入的功能。

           


          作者:caoyinghui1986 發(fā)表于2008-6-2 6:16:00 原文鏈接
          閱讀:5901 評(píng)論:6 查看評(píng)論

          posted @ 2008-06-01 22:16 shine_panda 閱讀(98) | 評(píng)論 (0)編輯 收藏

          WEB中加載ApplicationContext的兩種方式

          1,通過(guò)Listener加載ApplicationContext

           <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
           </context-param>
           <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
           </listener>

          -----------------------------------------------------------------------------------------------------------------------------------------

          通過(guò)Servlet加載ApplicationContext

                 <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
           </context-param>
           
           <servlet>
            <servlet-name>SpringContextServlet</servlet-name>
            <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
           </servlet>

          -------------------------------------------------------------------------------------------------------------------------------------------

          兩種加載方式中要特別注意 路徑問(wèn)題。
          <param-value>/WEB-INF/applicationContext.xml</param-value>
          其中要確保你的 WEB-INF 下 有 applicationContext.xml 這個(gè)文件
          測(cè)試發(fā)現(xiàn)WEB-INF區(qū)分大小寫。 空格好象沒(méi)有發(fā)現(xiàn)問(wèn)題。
          Listener 接口 是在  servelt2.3 版本被引入的 我機(jī)器的配置是Eclipse3.2 +Tomcate5.0+JDK1.5
          使用這個(gè)沒(méi)有問(wèn)題。
          還有一個(gè) applicationContext.xml 如果放在 WEB-INF目錄外似乎在這里
          哪怕是改成相應(yīng)的路徑好象也訪問(wèn)不到。
          servlet中可以通過(guò)
          ApplicationContext context = org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
          得到 context 對(duì)象。

           

          作者:caoyinghui1986 發(fā)表于2008-6-1 15:52:00 原文鏈接
          閱讀:492 評(píng)論:4 查看評(píng)論

          posted @ 2008-06-01 07:52 shine_panda 閱讀(159) | 評(píng)論 (0)編輯 收藏

          js日歷控件

          calendar.js
           
          --------------------------------------------------------------------------------

          <!--
          document.write("<div id=meizzCalendarLayer style='position: absolute; z-index: 9999; width: 144; height: 193; display: none'>");
          document.write("<iframe name=meizzCalendarIframe scrolling=no frameborder=0 width=100% height=100%></iframe></div>");
          function writeIframe()
          {
              var strIframe = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style>"+
              "*{font-size: 12px; font-family: 宋體}"+
              ".bg{  color: "+ WebCalendar.lightColor +"; cursor: default; background-color: "+ WebCalendar.darkColor +";}"+
              "table#tableMain{ width: 142; height: 180;}"+
              "table#tableWeek td{ color: "+ WebCalendar.lightColor +";}"+
              "table#tableDay  td{ font-weight: bold;}"+
              "td#meizzYearHead, td#meizzYearMonth{color: "+ WebCalendar.wordColor +"}"+
              ".out { text-align: center; border-top: 1px solid "+ WebCalendar.DarkBorder +"; border-left: 1px solid "+ WebCalendar.DarkBorder +";"+
              "border-right: 1px solid "+ WebCalendar.lightColor +"; border-bottom: 1px solid "+ WebCalendar.lightColor +";}"+
              ".over{ text-align: center; border-top: 1px solid #FFFFFF; border-left: 1px solid #FFFFFF;"+
              "border-bottom: 1px solid "+ WebCalendar.DarkBorder +"; border-right: 1px solid "+ WebCalendar.DarkBorder +"}"+
              "input{ border: 1px solid "+ WebCalendar.darkColor +"; padding-top: 1px; height: 18; cursor: hand;"+
              "       color:"+ WebCalendar.wordColor +"; background-color: "+ WebCalendar.btnBgColor +"}"+
              "</style></head><body onselectstart='return false' style='margin: 0px' oncontextmenu='return false'><form name=meizz>";

              if (WebCalendar.drag){ strIframe += "<scr"+"ipt language=javascript>"+
              "var drag=false, cx=0, cy=0, o = parent.WebCalendar.calendar; function document.onmousemove(){"+
              "if(parent.WebCalendar.drag && drag){if(o.style.left=='')o.style.left=0; if(o.style.top=='')o.style.top=0;"+
              "o.style.left = parseInt(o.style.left) + window.event.clientX-cx;"+
              "o.style.top  = parseInt(o.style.top)  + window.event.clientY-cy;}}"+
              "function document.onkeydown(){ switch(window.event.keyCode){  case 27 : parent.hiddenCalendar(); break;"+
              "case 37 : parent.prevM(); break; case 38 : parent.prevY(); break; case 39 : parent.nextM(); break; case 40 : parent.nextY(); break;"+
              "case 84 : document.forms[0].today.click(); break;} window.event.keyCode = 0; window.event.returnValue= false;}"+
              "function dragStart(){cx=window.event.clientX; cy=window.event.clientY; drag=true;}</scr"+"ipt>"}

              strIframe += "<select name=tmpYearSelect  onblur='parent.hiddenSelect(this)' style='z-index:1;position:absolute;top:3;left:18;display:none'"+
              " onchange='parent.WebCalendar.thisYear =this.value; parent.hiddenSelect(this); parent.writeCalendar();'></select>"+
              "<select name=tmpMonthSelect onblur='parent.hiddenSelect(this)' style='z-index:1; position:absolute;top:3;left:74;display:none'"+
              " onchange='parent.WebCalendar.thisMonth=this.value; parent.hiddenSelect(this); parent.writeCalendar();'></select>"+

              "<table id=tableMain class=bg border=0 cellspacing=2 cellpadding=0>"+
              "<tr><td width=140 height=19 bgcolor='"+ WebCalendar.lightColor +"'>"+
              "    <table width=140 id=tableHead border=0 cellspacing=1 cellpadding=0><tr align=center>"+
              "    <td width=15 height=19 class=bg title='向前翻 1 月&#13;快捷鍵:←' style='cursor: hand' onclick='parent.prevM()'><b>&lt;</b></td>"+
              "    <td width=60 id=meizzYearHead  title='點(diǎn)擊此處選擇年份' onclick='parent.funYearSelect(parseInt(this.innerText, 10))'"+
              "        onmouseover='this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor'"+
              "        onmouseout='this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor'></td>"+
              "    <td width=50 id=meizzYearMonth title='點(diǎn)擊此處選擇月份' onclick='parent.funMonthSelect(parseInt(this.innerText, 10))'"+
              "        onmouseover='this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor'"+
              "        onmouseout='this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor'></td>"+
              "    <td width=15 class=bg title='向后翻 1 月&#13;快捷鍵:→' onclick='parent.nextM()' style='cursor: hand'><b>&gt;</b></td></tr></table>"+
              "</td></tr><tr><td height=20><table id=tableWeek border=1 width=140 cellpadding=0 cellspacing=0 ";
              if(WebCalendar.drag){strIframe += "onmousedown='dragStart()' onmouseup='drag=false' onmouseout='drag=false'";}
              strIframe += " borderColorLight='"+ WebCalendar.darkColor +"' borderColorDark='"+ WebCalendar.lightColor +"'>"+
              "    <tr align=center><td height=20>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr></table>"+
              "</td></tr><tr><td valign=top width=140 bgcolor='"+ WebCalendar.lightColor +"'>"+
              "    <table id=tableDay height=120 width=140 border=0 cellspacing=1 cellpadding=0>";
                   for(var x=0; x<5; x++){ strIframe += "<tr>";
                   for(var y=0; y<7; y++)  strIframe += "<td class=out id='meizzDay"+ (x*7+y) +"'></td>"; strIframe += "</tr>";}
                   strIframe += "<tr>";
                   for(var x=35; x<39; x++) strIframe += "<td class=out id='meizzDay"+ x +"'></td>";
                   strIframe +="<td colspan=3 class=out title='"+ WebCalendar.regInfo +"'><input style=' background-color: "+
                   WebCalendar.btnBgColor +";cursor: hand; padding-top: 4px; width: 100%; height: 100%; border: 0' onfocus='this.blur()'"+
                   " type=button value='&nbsp; &nbsp; 關(guān)閉' onclick='parent.hiddenCalendar()'></td></tr></table>"+
              "</td></tr><tr><td height=20 width=140 bgcolor='"+ WebCalendar.lightColor +"'>"+
              "    <table border=0 cellpadding=1 cellspacing=0 width=140>"+
              "    <tr><td><input name=prevYear title='向前翻 1 年&#13;快捷鍵:↑' onclick='parent.prevY()' type=button value='&lt;&lt;'"+
              "    onfocus='this.blur()' style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==1000)'><input"+
              "    onfocus='this.blur()' name=prevMonth title='向前翻 1 月&#13;快捷鍵:←' onclick='parent.prevM()' type=button value='&lt;&nbsp;'>"+
              "    </td><td align=center><input name=today type=button value='Today' onfocus='this.blur()' style='width: 50' title='當(dāng)前日期&#13;快捷鍵:T'"+
              "    onclick=/"parent.returnDate(new Date().getDate() +'/'+ (new Date().getMonth() +1) +'/'+ new Date().getFullYear())/">"+
              "    </td><td align=right><input title='向后翻 1 月&#13;快捷鍵:→' name=nextMonth onclick='parent.nextM()' type=button value='&nbsp;&gt;'"+
              "    onfocus='this.blur()'><input name=nextYear title='向后翻 1 年&#13;快捷鍵:↓' onclick='parent.nextY()' type=button value='&gt;&gt;'"+
              "    onfocus='this.blur()' style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==9999)'></td></tr></table>"+
              "</td></tr><table></form></body></html>";
              with(WebCalendar.iframe)
              {
                  document.writeln(strIframe); document.close();
                  for(var i=0; i<39; i++)
                  {
                      WebCalendar.dayObj[i] = eval("meizzDay"+ i);
                      WebCalendar.dayObj[i].onmouseover = dayMouseOver;
                      WebCalendar.dayObj[i].onmouseout  = dayMouseOut;
                      WebCalendar.dayObj[i].onclick     = returnDate;
                  }
              }
          }
          function WebCalendar() //初始化日歷的設(shè)置
          {
              this.regInfo    = "WEB Calendar ver 3.0&#13;作者:meizz(梅花雪疏影橫斜)&#13;網(wǎng)站:http://www.meizz.com/&#13;關(guān)閉的快捷鍵:[Esc]";
              this.regInfo   += "&#13;&#13;Ver 2.0:walkingpoison(水晶龍)&#13;Ver 1.0:meizz(梅花雪疏影橫斜)";
              this.daysMonth  = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
              this.day        = new Array(39);            //定義日歷展示用的數(shù)組
              this.dayObj     = new Array(39);            //定義日期展示控件數(shù)組
              this.dateStyle  = null;                     //保存格式化后日期數(shù)組
              this.objExport  = null;                     //日歷回傳的顯示控件
              this.eventSrc   = null;                     //日歷顯示的觸發(fā)控件
              this.inputDate  = null;                     //轉(zhuǎn)化外的輸入的日期(d/m/yyyy)
              this.thisYear   = new Date().getFullYear(); //定義年的變量的初始值
              this.thisMonth  = new Date().getMonth()+ 1; //定義月的變量的初始值
              this.thisDay    = new Date().getDate();     //定義日的變量的初始值
              this.today      = this.thisDay +"/"+ this.thisMonth +"/"+ this.thisYear;   //今天(d/m/yyyy)
              this.iframe     = window.frames("meizzCalendarIframe"); //日歷的 iframe 載體
              this.calendar   = getObjectById("meizzCalendarLayer");  //日歷的層
              this.dateReg    = "";           //日歷格式驗(yàn)證的正則式

              this.yearFall   = 50;           //定義年下拉框的年差值
              this.format     = "yyyy-mm-dd"; //回傳日期的格式
              this.timeShow   = false;        //是否返回時(shí)間
              this.drag       = true;         //是否允許拖動(dòng)
              this.darkColor  = "#FF6347";    //控件的暗色
              this.lightColor = "#FFFFFF";    //控件的亮色
              this.btnBgColor = "#FFF5A0";    //控件的按鈕背景色
              this.wordColor  = "#000040";    //控件的文字顏色
              this.wordDark   = "#DCDCDC";    //控件的暗文字顏色
              this.dayBgColor = "#FFFACD";    //日期數(shù)字背景色
              this.todayColor = "#FF9933";    //今天在日歷上的標(biāo)示背景色
              this.DarkBorder = "#FFE4C4";    //日期顯示的立體表達(dá)色
          }   var WebCalendar = new WebCalendar();

          function calendar() //主調(diào)函數(shù)
          {
              var e = window.event.srcElement;   writeIframe();
              var o = WebCalendar.calendar.style; WebCalendar.eventSrc = e;
           if (arguments.length == 0) WebCalendar.objExport = e;
              else WebCalendar.objExport = eval(arguments[0]);

              WebCalendar.iframe.tableWeek.style.cursor = WebCalendar.drag ? "move" : "default";
           var t = e.offsetTop,  h = e.clientHeight, l = e.offsetLeft, p = e.type;
           while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}
              o.display = ""; WebCalendar.iframe.document.body.focus();
              var cw = WebCalendar.calendar.clientWidth, ch = WebCalendar.calendar.clientHeight;
              var dw = document.body.clientWidth, dl = document.body.scrollLeft, dt = document.body.scrollTop;
             
              if (document.body.clientHeight + dt - t - h >= ch) o.top = (p=="image")? t + h : t + h + 6;
              else o.top  = (t - dt < ch) ? ((p=="image")? t + h : t + h + 6) : t - ch;
              if (dw + dl - l >= cw) o.left = l; else o.left = (dw >= cw) ? dw - cw + dl : dl;

              if  (!WebCalendar.timeShow) WebCalendar.dateReg = /^(/d{1,4})(-|//|.)(/d{1,2})/2(/d{1,2})$/;
              else WebCalendar.dateReg = /^(/d{1,4})(-|//|.)(/d{1,2})/2(/d{1,2}) (/d{1,2}):(/d{1,2}):(/d{1,2})$/;

              try{
                  if (WebCalendar.objExport.value.trim() != ""){
                      WebCalendar.dateStyle = WebCalendar.objExport.value.trim().match(WebCalendar.dateReg);
                      if (WebCalendar.dateStyle == null)
                      {
                          WebCalendar.thisYear   = new Date().getFullYear();
                          WebCalendar.thisMonth  = new Date().getMonth()+ 1;
                          WebCalendar.thisDay    = new Date().getDate();
                          alert("原文本框里的日期有錯(cuò)誤!/n可能與你定義的顯示時(shí)分秒有沖突!");
                          writeCalendar(); return false;
                      }
                      else
                      {
                          WebCalendar.thisYear   = parseInt(WebCalendar.dateStyle[1], 10);
                          WebCalendar.thisMonth  = parseInt(WebCalendar.dateStyle[3], 10);
                          WebCalendar.thisDay    = parseInt(WebCalendar.dateStyle[4], 10);
                          WebCalendar.inputDate  = parseInt(WebCalendar.thisDay, 10) +"/"+ parseInt(WebCalendar.thisMonth, 10) +"/"+
                          parseInt(WebCalendar.thisYear, 10); writeCalendar();
                      }
                  }  else writeCalendar();
              }  catch(e){writeCalendar();}
          }
          function funMonthSelect() //月份的下拉框
          {
              var m = isNaN(parseInt(WebCalendar.thisMonth, 10)) ? new Date().getMonth() + 1 : parseInt(WebCalendar.thisMonth);
              var e = WebCalendar.iframe.document.forms[0].tmpMonthSelect;
              for (var i=1; i<13; i++) e.options.add(new Option(i +"月", i));
              e.style.display = ""; e.value = m; e.focus(); window.status = e.style.top;
          }
          function funYearSelect() //年份的下拉框
          {
              var n = WebCalendar.yearFall;
              var e = WebCalendar.iframe.document.forms[0].tmpYearSelect;
              var y = isNaN(parseInt(WebCalendar.thisYear, 10)) ? new Date().getFullYear() : parseInt(WebCalendar.thisYear);
                  y = (y <= 1000)? 1000 : ((y >= 9999)? 9999 : y);
              var min = (y - n >= 1000) ? y - n : 1000;
              var max = (y + n <= 9999) ? y + n : 9999;
                  min = (max == 9999) ? max-n*2 : min;
                  max = (min == 1000) ? min+n*2 : max;
              for (var i=min; i<=max; i++) e.options.add(new Option(i +"年", i));
              e.style.display = ""; e.value = y; e.focus();
          }
          function prevM()  //往前翻月份
          {
              WebCalendar.thisDay = 1;
              if (WebCalendar.thisMonth==1)
              {
                  WebCalendar.thisYear--;
                  WebCalendar.thisMonth=13;
              }
              WebCalendar.thisMonth--; writeCalendar();
          }
          function nextM()  //往后翻月份
          {
              WebCalendar.thisDay = 1;
              if (WebCalendar.thisMonth==12)
              {
                  WebCalendar.thisYear++;
                  WebCalendar.thisMonth=0;
              }
              WebCalendar.thisMonth++; writeCalendar();
          }
          function prevY(){WebCalendar.thisDay = 1; WebCalendar.thisYear--; writeCalendar();}//往前翻 Year
          function nextY(){WebCalendar.thisDay = 1; WebCalendar.thisYear++; writeCalendar();}//往后翻 Year
          function hiddenSelect(e){for(var i=e.options.length; i>-1; i--)e.options.remove(i); e.style.display="none";}
          function getObjectById(id){ if(document.all) return(eval("document.all."+ id)); return(eval(id)); }
          function hiddenCalendar(){getObjectById("meizzCalendarLayer").style.display = "none";};
          function appendZero(n){return(("00"+ n).substr(("00"+ n).length-2));}//日期自動(dòng)補(bǔ)零程序
          function String.prototype.trim(){return this.replace(/(^/s*)|(/s*$)/g,"");}
          function dayMouseOver()
          {
              this.className = "over";
              this.style.backgroundColor = WebCalendar.darkColor;
              if(WebCalendar.day[this.id.substr(8)].split("/")[1] == WebCalendar.thisMonth)
              this.style.color = WebCalendar.lightColor;
          }
          function dayMouseOut()
          {
              this.className = "out"; var d = WebCalendar.day[this.id.substr(8)], a = d.split("/");
              this.style.removeAttribute('backgroundColor');
              if(a[1] == WebCalendar.thisMonth && d != WebCalendar.today)
              {
                  if(WebCalendar.dateStyle && a[0] == parseInt(WebCalendar.dateStyle[4], 10))
                  this.style.color = WebCalendar.lightColor;
                  this.style.color = WebCalendar.wordColor;
              }
          }
          function writeCalendar() //對(duì)日歷顯示的數(shù)據(jù)的處理程序
          {
              var y = WebCalendar.thisYear;
              var m = WebCalendar.thisMonth;
              var d = WebCalendar.thisDay;
              WebCalendar.daysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28;
              if (!(y<=9999 && y >= 1000 && parseInt(m, 10)>0 && parseInt(m, 10)<13 && parseInt(d, 10)>0)){
                  alert("對(duì)不起,你輸入了錯(cuò)誤的日期!");
                  WebCalendar.thisYear   = new Date().getFullYear();
                  WebCalendar.thisMonth  = new Date().getMonth()+ 1;
                  WebCalendar.thisDay    = new Date().getDate(); }
              y = WebCalendar.thisYear;
              m = WebCalendar.thisMonth;
              d = WebCalendar.thisDay;
              WebCalendar.iframe.meizzYearHead.innerText  = y +" 年";
              WebCalendar.iframe.meizzYearMonth.innerText = parseInt(m, 10) +" 月";
              WebCalendar.daysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28; //閏年二月為29天
              var w = new Date(y, m-1, 1).getDay();
              var prevDays = m==1  ? WebCalendar.daysMonth[11] : WebCalendar.daysMonth[m-2];
              for(var i=(w-1); i>=0; i--) //這三個(gè) for 循環(huán)為日歷賦數(shù)據(jù)源(數(shù)組 WebCalendar.day)格式是 d/m/yyyy
              {
                  WebCalendar.day[i] = prevDays +"/"+ (parseInt(m, 10)-1) +"/"+ y;
                  if(m==1) WebCalendar.day[i] = prevDays +"/"+ 12 +"/"+ (parseInt(y, 10)-1);
                  prevDays--;
              }
              for(var i=1; i<=WebCalendar.daysMonth[m-1]; i++) WebCalendar.day[i+w-1] = i +"/"+ m +"/"+ y;
              for(var i=1; i<39-w-WebCalendar.daysMonth[m-1]+1; i++)
              {
                  WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +"/"+ (parseInt(m, 10)+1) +"/"+ y;
                  if(m==12) WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +"/"+ 1 +"/"+ (parseInt(y, 10)+1);
              }
              for(var i=0; i<39; i++)    //這個(gè)循環(huán)是根據(jù)源數(shù)組寫到日歷里顯示
              {
                  var a = WebCalendar.day[i].split("/");
                  WebCalendar.dayObj[i].innerText    = a[0];
                  WebCalendar.dayObj[i].title        = a[2] +"-"+ appendZero(a[1]) +"-"+ appendZero(a[0]);
                  WebCalendar.dayObj[i].bgColor      = WebCalendar.dayBgColor;
                  WebCalendar.dayObj[i].style.color  = WebCalendar.wordColor;
                  if ((i<10 && parseInt(WebCalendar.day[i], 10)>20) || (i>27 && parseInt(WebCalendar.day[i], 10)<12))
                      WebCalendar.dayObj[i].style.color = WebCalendar.wordDark;
                  if (WebCalendar.inputDate==WebCalendar.day[i])    //設(shè)置輸入框里的日期在日歷上的顏色
                  {WebCalendar.dayObj[i].bgColor = WebCalendar.darkColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}
                  if (WebCalendar.day[i] == WebCalendar.today)      //設(shè)置今天在日歷上反應(yīng)出來(lái)的顏色
                  {WebCalendar.dayObj[i].bgColor = WebCalendar.todayColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}
              }
          }
          function returnDate() //根據(jù)日期格式等返回用戶選定的日期
          {
              if(WebCalendar.objExport)
              {
                  var returnValue;
                  var a = (arguments.length==0) ? WebCalendar.day[this.id.substr(8)].split("/") : arguments[0].split("/");
                  var d = WebCalendar.format.match(/^(/w{4})(-|//|.|)(/w{1,2})/2(/w{1,2})$/);
                  if(d==null){alert("你設(shè)定的日期輸出格式不對(duì)!/r/n/r/n請(qǐng)重新定義 WebCalendar.format !"); return false;}
                  var flag = d[3].length==2 || d[4].length==2; //判斷返回的日期格式是否要補(bǔ)零
                  returnValue = flag ? a[2] +d[2]+ appendZero(a[1]) +d[2]+ appendZero(a[0]) : a[2] +d[2]+ a[1] +d[2]+ a[0];
                  if(WebCalendar.timeShow)
                  {
                      var h = new Date().getHours(), m = new Date().getMinutes(), s = new Date().getSeconds();
                      returnValue += flag ? " "+ appendZero(h) +":"+ appendZero(m) +":"+ appendZero(s) : " "+  h  +":"+ m +":"+ s;
                  }
                  WebCalendar.objExport.value = returnValue;
                  hiddenCalendar();
              }
          }
          function document.onclick()
          {
              if(WebCalendar.eventSrc != window.event.srcElement) hiddenCalendar();
          }
          //-->

          ----------------------------------------------------------------------------------------------------------------------------------------------

          <SCRIPT LANGUAGE="JavaScript" src="calendar.js"></SCRIPT>
          在你的頁(yè)面中引入 這個(gè) js 文件
          通過(guò)onfocus來(lái)調(diào)用并顯示日歷
          <input type="text" onfocus="calendar()" name="xxx">
          當(dāng)把一個(gè)帶中文的js文件考到Eclipse工程時(shí)候會(huì)報(bào)編碼錯(cuò)誤這是 需要點(diǎn)右鍵 屬性 更改編碼。然后粘貼就可以
          如果粘貼出現(xiàn)亂碼  http://d.download.csdn.net/down/476931/caoyinghui1986 
          有完整的JS文件 js文件中出錯(cuò)的地方可以用 <!-- --> 注釋. (JBuilder2005不報(bào)錯(cuò) ,Eclipse好象有這個(gè)問(wèn)題)
          注釋 后就沒(méi)有事情了。
           
           
           
          作者:caoyinghui1986 發(fā)表于2008-5-31 17:56:00 原文鏈接
          閱讀:907 評(píng)論:2 查看評(píng)論

          posted @ 2008-05-31 09:56 shine_panda 閱讀(1188) | 評(píng)論 (0)編輯 收藏

          合并連續(xù)數(shù)字的算法

          public class Test {
          	public static void main(String[] args) {
          		String str = new String(
          				"1,2,3,4,5,6,7,8,9,11,13,14,1000,1001,1002,1003");
          		String[] s = str.split(",");
          		int[] num = new int[s.length];
          		String result = "";
          		for (int i = 0; i < s.length; i++) {
          			num[i] = Integer.parseInt(s[i]);
          		}
          		for (int i = 0; i < num.length; i++) {
          			if (i == 0) {
          				result = "" + num[i];
          			} else if (i == num.length - 1) {
          				if (num[i] - num[i - 1] == 1) {
          					result = result + "-" + num[i];
          				} else {
          					result = result + "," + num[i];
          				}
          			} else {
          				if ((num[i] - num[i - 1] == 1) && (num[i + 1] - num[i] == 1)) {
          					continue;
          				}
          				if ((num[i] - num[i - 1] == 1) && (num[i + 1] - num[i] != 1)) {
          					result = result + "-" + num[i];
          				}
          				if ((num[i] - num[i - 1] != 1)) {
          					result = result + "," + num[i];
          				}
          
          			}
          
          		}
          		System.out.println(result);
          	}
          }
          作者:caoyinghui1986 發(fā)表于2008-5-31 14:11:00 原文鏈接
          閱讀:288 評(píng)論:1 查看評(píng)論

          posted @ 2008-05-31 06:11 shine_panda 閱讀(259) | 評(píng)論 (0)編輯 收藏

          Sping中自定義屬性編輯器

          Spring通過(guò)PropertyEdit(屬性編輯器) 可以將字符串轉(zhuǎn)換為真實(shí)類型。通過(guò)CustomEditorConfigurer ,ApplicationContext 可以很方便的支持自定義
          PropertyEdit。


          MyType.java

          package com.cao.spring.applicationContext;

          public class MyType {
           private String text;
           
           public MyType(String text){
            this.text = text;
           }
           
           public String getText(){
            return this.text;
           }
          }
           
           
          DependsOnType.java
           
          package com.cao.spring.applicationContext;

          public class DependsOnType {
           private MyType type;

           public MyType getType() {
            return type;
           }

           public void setType(MyType type) {
            this.type = type;
           }
           
          }
           
          //自定義的屬性編輯器MyTypeEdit.java
           
          package com.cao.spring.applicationContext;

          public class MyTypeEdit extends java.beans.PropertyEditorSupport{
           //提供一種對(duì)字符串的轉(zhuǎn)換策略
           private String format;
           
           
           public String getFormat() {
            return format;
           }


           public void setFormat(String format) {
            this.format = format;
           }


           //覆蓋父類(PropertyEditorSupport)的setAsText方法。
            public void setAsText(String text) {
             if(format!=null && format.equals("upperCase")){
              System.out.println("修改前的樣子:"+text);
              text=text.toUpperCase();
             }
            
            //獲得編輯前的類型
             System.out.println("獲得編輯前的類型 "+text.getClass().getSimpleName());
            //包裝成真實(shí)類型
             MyType type = new MyType(text);
            //注入包裝后的類型
             setValue(type); 
              }
          }

           

           
          配置bean   propertyEdit.xml

           
          <beans>
             <bean id="myBean" class="com.cao.spring.applicationContext.DependsOnType">
             <!-- type的真實(shí)類型是 MyType 但這里指定的是一個(gè)普通的String --> 
                 <property name="type">
                     <value>abc</value>
                </property>
              </bean>
          </beans>

           

           
          將屬性編輯器配置進(jìn)來(lái) plugin.xml
          <bean id="aaa" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
                <property name="customEditors">  
                    <map>       <!-- key指定了轉(zhuǎn)換后的類型 -->  
              <entry key="com.cao.spring.applicationContext.MyType">   
                        <!-- 內(nèi)部bean 配置了自定義的屬性編輯器 -->  
                       <bean class="com.cao.spring.applicationContext.MyTypeEdit">     
                         <!-- 配置字符串的轉(zhuǎn)換策略 -->    
                       <property name="format" value="upperCase"/>  
                      </bean>  
                   </entry>  
                    </map> 
                </property>
          </bean>


           
          測(cè)試類:
          public class MyEditorTest {
           public static void main(String[] args) {
            ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"application/plugin.xml","application/propertyEdit.xml"});
            DependsOnType type=  (DependsOnType) ctx.getBean("myBean");
            System.out.println(type.getType().getClass().getSimpleName());
            System.out.println(type.getType().getText());
           }
          }
           
          //輸出結(jié)果:
          修改前的樣子:abc獲得編輯前的類型 StringMyTypeABC

           

          作者:caoyinghui1986 發(fā)表于2008-5-30 20:44:00 原文鏈接
          閱讀:311 評(píng)論:0 查看評(píng)論

          posted @ 2008-05-30 12:44 shine_panda 閱讀(123) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共3頁(yè): 上一頁(yè) 1 2 3 
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 肇源县| 犍为县| 大石桥市| 海宁市| 额敏县| 陆川县| 陈巴尔虎旗| 赤壁市| 黎城县| 隆回县| 柞水县| 武安市| 双江| 台南市| 连城县| 武夷山市| 平原县| 新邵县| 新泰市| 始兴县| 涪陵区| 武夷山市| 双辽市| 大田县| 潞城市| 昭苏县| 咸宁市| 铁岭市| 绥阳县| 浮梁县| 岳池县| 江都市| 龙陵县| 蒙阴县| 城固县| 彩票| 沅陵县| 华蓥市| 织金县| 桑日县| 蒲城县|