<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    caoyinghui

    模式窗口的使用

    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script>  //補充完成下邊的函數(shù),打開新的一個模式窗口  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>補充完成openShowModalDialog函數(shù),打開新的一個模式窗口</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>

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

         window.close();  }   </script>

    </head>

    <body>

    <h1>模式窗口的使用:</h1> <h3>補充完成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 評論:0 查看評論

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

    框架中取值問題

    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>  //補充完成此函數(shù),用于刷新Menu窗體的頁面  function flushMenuFrame(){      //top表示頂級窗口 的 window對象   window.top.menu.location.href="DEMO03_menu.html";  }  

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

    </head>

    <body> <center>BAR頁面</center> <button onclick="flushMenuFrame();">刷新框架Menu窗口的頁面</button> Bar頁面的文本框:<input type="text" id="barText" value="Bar頁面的值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頁面的值2"> </body> </html>

     

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

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

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

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

    index.jsp

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

    一個簡單的表單用于瀏覽圖片

    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> 對這個servlet的配置)

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

      response.setContentType("text/html");
      //PrintWriter out2 = response.getWriter();
      //servlet 中 out 對象只可取一次.
      
      //如果要用與輸出二進制數(shù)據(jù) . 就必須用 OutputStream 對象.
      
      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>

     

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

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

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

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

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

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


    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中獲得這個連接的方式。
    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 連接池 時除了要注意 導入必要的 3個連接池驅(qū)動包外 還要引入sql的三個驅(qū)動包。

     

    -------------------------------------------------------------------------------------------------------------------------------
    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 文件來定義連接信息。

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

    <bean id="aa" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <!-- 對與單個文件 這里可以直接用 location屬性 然后給一個 value單值 原因是因為在其 父類的實現(xiàn)中
       PropertiesLoaderSupport 有個 setLocation方法.
        public void setLocation(Resource location) {
            this.locations = new Resource[] {location};
           }
         
          public void setLocations(Resource[] locations) {
         this.locations = locations;
              }
           所以單個文件可以簡單的用 location對應一個 值(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>

     

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

     

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

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


    自己在配置這個東西的時候搞了好久 ,最后還是求助 CSDN解決的
    貼子http://topic.csdn.net/u/20080605/20/7fdd0eee-9c43-428a-8b82-5db9a1968151.html
    總結(jié)下幾個需要注意的地方:
    1,首先在 tomcate 的server.xml文件中正確配置
    2,要將相關(guān)的驅(qū)動包(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();
             
           }

    通過這兩步配置后你就可以用 http://localhost:8080/testPool/來訪問 你的資源 testPool 是你在 <Context path="/testPool"/> 中path的值匹配


    如果你吧你的項目部署到tomcate還是不能獲得連接。 這是你要在 C:/Tomcat 5.5/conf/Catalina/localhost 下新建一個xml 文件 (tomcatePool.xml)
    tomcatePool 是你的當前項目的名字。
    這樣就可以通過 http://localhost:8080/tomcatePool/ 來訪問你的資源了。這時 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 因為是通過項目名來訪問的所以這兩個值沒有意義。


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

    只要加 一個配置。
    hibernate.cfg.xml文件

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

    有了這個后
    <!-- <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>-->

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

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

    目前就只做了這么多 以后遇到了新的再來補充.

     

     

     

     

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

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

    Hibernate映射類型對照表

    Hibernate映射類型對照表
    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的某個實例 serializable varbinary(或blob)
    java.lang.String string varchar
    java.lang.String text clob
    java.util.Date 或 java.sql.Timestamp time timestamp

    從書上把這個表抄下來方便以后查閱.

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

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

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

    Spring 和struts 整合的三種方式

    Spring 和 struts 整合的三種方式。

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

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

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


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

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

    這是一個 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  對象             
      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耦合在一起。
    但實現(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"/> 通過 <controller >來替代
                            org.apache.struts.action.RequestProcessor 的請求處理。

    public class LoginAction extends Action {
     //利用spring來注入這個對象。
     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
      //這樣一改這行代碼似乎沒有必要了。
      //WebApplicationContext ctx = this.getWebApplicationContext();
      //LoginDao dao = (LoginDao) ctx.getBean("loginDao");
     
      User u = new User();
      
      u.setName(loginForm.getName());
      u.setPwd(loginForm.getPwd());
      
      //直接用dao來調(diào)用spring會將這個對象實例化。
      if(dao.checkLogin(u)){
       return mapping.findForward("success");
      }else{
       return  mapping.findForward("error");
      }
      
     }
    }
    這里的。
    LoginAction extends Action 說明 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)建和對象的依賴注入全部由IOC容器來完成。 使用Spring的DelegatingAcionProxy來幫助實現(xiàn)代理的工作
    org.springframework.web.struts.DelegatingActiongProxy繼承于org.apache.struts.action.Action .


    全權(quán)委托的配置方式同 方式 2 類似 (applcationContext.xml文件的配置和 Action類的實現(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,第一種使得過多的耦合了Spring和Action .
    2,RequestProcessor類已經(jīng)被代理 如果要再實現(xiàn)自己的實現(xiàn)方式(如:編碼處理)怕有點麻煩。

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

     


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

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

    WEB中加載ApplicationContext的兩種方式

    1,通過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>

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

    通過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>

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

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

     

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

    posted @ 2008-06-01 07:52 shine_panda 閱讀(157) | 評論 (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='點擊此處選擇年份' 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='點擊此處選擇月份' 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='當前日期&#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    = "";           //日歷格式驗證的正則式

        this.yearFall   = 50;           //定義年下拉框的年差值
        this.format     = "yyyy-mm-dd"; //回傳日期的格式
        this.timeShow   = false;        //是否返回時間
        this.drag       = true;         //是否允許拖動
        this.darkColor  = "#FF6347";    //控件的暗色
        this.lightColor = "#FFFFFF";    //控件的亮色
        this.btnBgColor = "#FFF5A0";    //控件的按鈕背景色
        this.wordColor  = "#000040";    //控件的文字顏色
        this.wordDark   = "#DCDCDC";    //控件的暗文字顏色
        this.dayBgColor = "#FFFACD";    //日期數(shù)字背景色
        this.todayColor = "#FF9933";    //今天在日歷上的標示背景色
        this.DarkBorder = "#FFE4C4";    //日期顯示的立體表達色
    }   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("原文本框里的日期有錯誤!/n可能與你定義的顯示時分秒有沖突!");
                    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));}//日期自動補零程序
    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() //對日歷顯示的數(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("對不起,你輸入了錯誤的日期!");
            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--) //這三個 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++)    //這個循環(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è)置今天在日歷上反應出來的顏色
            {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è)定的日期輸出格式不對!/r/n/r/n請重新定義 WebCalendar.format !"); return false;}
            var flag = d[3].length==2 || d[4].length==2; //判斷返回的日期格式是否要補零
            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>
    在你的頁面中引入 這個 js 文件
    通過onfocus來調(diào)用并顯示日歷
    <input type="text" onfocus="calendar()" name="xxx">
    當把一個帶中文的js文件考到Eclipse工程時候會報編碼錯誤這是 需要點右鍵 屬性 更改編碼。然后粘貼就可以
    如果粘貼出現(xiàn)亂碼  http://d.download.csdn.net/down/476931/caoyinghui1986 
    有完整的JS文件 js文件中出錯的地方可以用 <!-- --> 注釋. (JBuilder2005不報錯 ,Eclipse好象有這個問題)
    注釋 后就沒有事情了。
     
     
     
    作者:caoyinghui1986 發(fā)表于2008-5-31 17:56:00 原文鏈接
    閱讀:907 評論:2 查看評論

    posted @ 2008-05-31 09:56 shine_panda 閱讀(1187) | 評論 (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 評論:1 查看評論

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

    Sping中自定義屬性編輯器

    Spring通過PropertyEdit(屬性編輯器) 可以將字符串轉(zhuǎn)換為真實類型。通過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{
     //提供一種對字符串的轉(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());
      //包裝成真實類型
       MyType type = new MyType(text);
      //注入包裝后的類型
       setValue(type); 
        }
    }

     

     
    配置bean   propertyEdit.xml

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

     

     
    將屬性編輯器配置進來 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>


     
    測試類:
    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 評論:0 查看評論

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

    僅列出標題
    共3頁: 上一頁 1 2 3 
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統(tǒng)計

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 4hu四虎最新免费地址| 精品久久久久久久免费加勒比| 亚洲资源在线观看| 97在线线免费观看视频在线观看| 亚洲人成人无码.www石榴| 一本色道久久88综合亚洲精品高清| 国产精品午夜免费观看网站 | 亚洲精彩视频在线观看| 四虎成人精品一区二区免费网站 | 亚洲冬月枫中文字幕在线看| 日本人护士免费xxxx视频| 成人免费av一区二区三区| 91亚洲精品自在在线观看| 亚洲男人在线无码视频| 国产成人精品免费视频大| 黄色免费在线网址| 亚洲精品自在线拍| 亚洲精品国产精品国自产观看| 最近2019年免费中文字幕高清 | 亚洲av女电影网| 四虎在线免费播放| 久久aⅴ免费观看| 精品免费AV一区二区三区| 亚洲精品国产成人99久久| 国产99视频精品免费视频7| 4虎1515hh永久免费| 一级毛片免费播放视频| 亚洲中字慕日产2021| 国产精品亚洲精品日韩已方| 67194成是人免费无码| 今天免费中文字幕视频| 亚洲AV网一区二区三区| 亚洲欧洲春色校园另类小说| 在线亚洲97se亚洲综合在线 | 免费国产真实迷j在线观看| 久久WWW免费人成一看片| 免费播放在线日本感人片| 特级aaaaaaaaa毛片免费视频| 亚洲欧美日韩中文无线码 | 久久久久久久久亚洲| 亚洲精品tv久久久久|