qiyadeng

          專注于Java示例及教程
          posts - 84, comments - 152, trackbacks - 0, articles - 34

          Denny 丹尼
          1.Denny這個名字讓人聯想到課堂上的笑蛋-愛玩友善極度幽默的年輕男孩,腦袋卻不太靈光。
          2.鄧是我本姓

          posted @ 2006-01-04 23:13 qiyadeng 閱讀(256) | 評論 (0)編輯 收藏

           這也是個開源的標簽庫^_^,因為老外總是很專業些寫了很多好東西,可是我基本上是和他們相反,即沒有時間也比較懶得。Struts-layout是一個用來擴充Struts的html標簽的作用的,我以前寫過(blog里)了怎么安裝使用的,這里就不說了。
          layoutselect.bmp
          1.這次我們先看JSP的結構:


            <head>
              <script src="/WebSample/config/javascript.js"></script>
            </head>
           
            <body>
            <html:form action="/country.do">
              <layout:select key="Country" property="countryId">    
            <layout:option value=""/>
            <layout:options collection="countries" property="countryId" labelProperty="name" sourceOf="cityId"/>
           </layout:select>
           
           <layout:select key="City" property="cityId">
            <layout:optionsDependent collection="cities" property="cityId" labelProperty="cityName" dependsFrom="countryId"/>
           </layout:select>
           <html:submit /><html:reset />
            </html:form> 
            </body>
          兩個select,其中第二個是<layout:optionsDependent/>它的dependsFrom的屬性需要和上面的那個select的property一致。countries是在request域的一個collection,而cities是countries的一個屬性,但是類型也是collection。
          2.Action:你需要Action來初始化countries,

           public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) { 
            List countries = new ArrayList();
            for(int i = 0 ;i< 10 ;i++){
             Country c = new Country();
             c.setCountryId(new Integer(i));
             c.setName("country"+i);
             for(int j = 0;j< 5 ;j++){
              c.addCity("city"+i+j,new Integer(i*10+j));
             }
             countries.add(c);
            }
            request.setAttribute("countries",countries);
            return mapping.findForward("success");
           }
          這樣你基本上就好了,夠簡單吧!下面還有兩個類的結構就是Country類和CityBean類:
          Country類:3個如下屬性,外加Setter/Getter方法。
           private String name;
           private List cities = new ArrayList();
           private Integer countryId;
          CityBean類:2個如下屬性,外加Setter/Getter方法。
           private Integer cityId;
           private String cityName;
          這些東西你當然還可以和數據庫結合起來使用,或是和XML文件結合起來使用。基本上一個應用最要需要考慮好
          類似Country類這個結構就可以了。

          這個標簽的方法是把所有的數據都會寫入到html文件中,并寫入相應的JavaScript,你可以查看源碼。


          <script>var countries = new Array();
          countries[0] = new Object();
          countries[0].value = "0";
          countries[0].cities = new Array();
          countries[0].cities[0] = new Object();
          countries[0].cities[0].value = "0";
          countries[0].cities[0].label = "city00";
          countries[0].cities[1] = new Object();
          countries[0].cities[1].value = "1";
          countries[0].cities[1].label = "city01";
          countries[0].cities[2] = new Object();
          countries[0].cities[2].value = "2";
          countries[0].cities[2].label = "city02";
          countries[0].cities[3] = new Object();
          countries[0].cities[3].value = "3";
          countries[0].cities[3].label = "city03";
          countries[0].cities[4] = new Object();
          countries[0].cities[4].value = "4";
          countries[0].cities[4].label = "city04"
          .....
          </script>

          個人總結,水平有限。主要是最近在論壇里看到不少關于這方面的問題,然后有沒有最后的答案,所以借助開源標簽可以做到通用性,希望對您有所幫助。

          posted @ 2005-12-26 17:16 qiyadeng 閱讀(1003) | 評論 (0)編輯 收藏


           看了一個開源的標簽庫AjaxTag(http://ajaxtags.sourceforge.net/index.html),提供幾個比較簡單的應用。我測試下了DropDownSelect應用:DropDown.BMP
           1、首先當然是看安裝文檔(http://ajaxtags.sourceforge.net/install.html),應該沒什么負責的,我要說的是第3步,也是比較重要的一步,創建服務端的控制程序。這部分也就是AjaxTag的原理,AjaxTag是通過服務器端的servelt生成XML文件,當然也可以是其他的服務器端技術只要是能生成格式良好的XML文件就可以了,文件格式如下圖:xml.BMP

           2、我們的例子就是通過選擇制造商可以動態的產生該制造商的車型。下面是需要的一些類文件:
           Car類:包含兩個String類型屬性make,model分別指制造商和車型.
           CarService類如下:


           public class CarService {

            static final List cars = new ArrayList();

            static {
              cars.add(new Car("Ford", "Escape"));
              cars.add(new Car("Ford", "Expedition"));
              cars.add(new Car("Ford", "Explorer"));
              cars.add(new Car("Ford", "Focus"));
              cars.add(new Car("Ford", "Mustang"));
              cars.add(new Car("Ford", "Thunderbird"));

              cars.add(new Car("Honda", "Accord"));
              cars.add(new Car("Honda", "Civic"));
              cars.add(new Car("Honda", "Element"));
              cars.add(new Car("Honda", "Ridgeline"));

              cars.add(new Car("Mazda", "Mazda 3"));
              cars.add(new Car("Mazda", "Mazda 6"));
              cars.add(new Car("Mazda", "RX-8"));
            }

            public CarService() {
              super();
            }
           /*該方法在servlet被調用*/
            public List getModelsByMake(String make) {
              List l = new ArrayList();
              for (Iterator iter = cars.iterator(); iter.hasNext();) {
                Car car = (Car) iter.next();
                if (car.getMake().equalsIgnoreCase(make)) {
                  l.add(car);
                }
              }
              return l;
            }

            public List getAllCars() {
              return cars;
            }
          }


          DropdownServlet類:

               String make = request.getParameter("make");
               CarService service = new CarService();
               //得到該make的所有model
               List list = service.getModelsByMake(make);
             //這就是Helper類,能生成像上面的xml文件
               return new AjaxXmlBuilder().addItems(list, "model", "make").toString();
          4、不要忘記了在web.xml中加上映射DropdownServlet

           <servlet>
              <servlet-name>dropdown</servlet-name>
              <servlet-class>qiya.deng.ajaxtag.DropdownServlet</servlet-class>
              <load-on-startup>2</load-on-startup>
            </servlet>

            <servlet-mapping>
              <servlet-name>dropdown</servlet-name>
              <url-pattern>/dropdown.view</url-pattern>
            </servlet-mapping>

          5.下面就是JSP部分(需要JSTL和EL):


          <c:set var="contextPath" scope="request">${pageContext.request.contextPath}</c:set>
          <form id="carForm" name="carForm">
            <fieldset>
              <legend>Choose Your Car</legend>

              <div>
                <img id="makerEmblem"
                     src="<%=request.getContextPath()%>/img/placeholder.gif"
                     width="76" height="29" />
              </div>

              <label for="make">Make:</label>
              <select id="make">
                <option value="">Select make</option>
                <option value="Ford">Ford</option>
                <option value="Honda">Honda</option>
                <option value="Mazda">Mazda</option>
                <option value="dummy">Dummy cars</option>
              </select>

              <label for="model">Model:</label>
              <select id="model" disabled="disabled">
                <option value="">Select model</option>
              </select>
            </fieldset>
          </form>
          <script type="text/javascript">
          function showMakerEmblem() {
            var index = document.forms["carForm"].make.selectedIndex;
            var automaker = document.forms["carForm"].make.options[index].text;
            var imgTag = document.getElementById("makerEmblem");
            if (index > 0) {
              imgTag.src = "<%=request.getContextPath()%>/img/" + automaker.toLowerCase() + "_logo.gif";
            }
          }
          function handleEmpty() {
            document.getElementById("model").options.length = 0;
            document.getElementById("model").options[0] = new Option("None", "");
            document.getElementById("model").disabled = true;
          }
          </script>
          <ajax:select
            baseUrl="${contextPath}/dropdown.view"
            source="make"
            target="model"
            parameters="make={make}"
            postFunction="showMakerEmblem"
           

          emptyFunction="handleEmpty" />
          注意到form里面其實沒什么不一樣的,就是最后那段的<ajax:select/>,baseUrl就是服務器端處理的Handler,source是關聯的源,model是被關聯的;parameter是傳個servlet的參數,可以有多個用逗號隔開;postFunction,emptyFunctuion就是上面的兩個JavaScript.詳細的可以看http://ajaxtags.sourceforge.net/usage.html

           經過簡單的修改,我們也可以把這個應用到Struts中。那就后續吧^_^...

          posted @ 2005-12-26 16:23 qiyadeng 閱讀(2396) | 評論 (0)編輯 收藏

          一個很有意義的計算題!
          如果令 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 分別等于百分之
          1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
              那麼Hard work (努力工作)
              H+A+R+D+W+O+R+K =8+1+18+4+23+15+18+11 = 98%
              Knowledge(知識)
              K+N+O+W+L+E+D+G+E =11+14+15+23+12+5+4+7+5 = 96%
              Love(愛情)
              L+O+V+E12+15+22+5 = 54%
              Luck(好運)
              L+U+C+K=12+21+3+11 = 47%
              (這些我們通常認為重要的東西往往並不是最重要的)
              什麼能使得生活變得圓滿?
              是Money(金錢)嗎? ...
              不! M+O+N+E+Y = 13+15+14+5+25 = 72%
              是Leadership(領導能力)嗎? ...
              不! L+E+A+D+E+R+S+H+I+P = 12+5+1+4+5+18+19+9+16 = 89%
              那麼,什麼能使生活變成100%的圓滿呢?
              每個問題都有其解決之道,只要你把目光放得遠一點!
              ATTITUDE(心態)
              A+T+T+I+T+U+D+E =1+20+20+9+20+21+4+5 = 100%
              我們對待工作、生活的態度能夠使我們的生活達到100%的圓滿。

          posted @ 2005-12-01 08:55 qiyadeng 閱讀(292) | 評論 (0)編輯 收藏


          我的性格,不知道準不準確。測試
          test.jpg

          posted @ 2005-11-27 09:45 qiyadeng 閱讀(484) | 評論 (2)編輯 收藏

                1.生活是不公平的,要去適應它;

            2.這世界并不會在意你的自尊,這世界指望你在自我感覺良好之前先要有所成就;

            3.高中剛畢業你不會成為一個公司的副總裁,直到你將此職位掙到手;

           
            4.如果你認為你的老師嚴厲,等你當了老板再這樣想;

            5.如果你陷入困境,不要尖聲抱怨錯誤,要從中吸取教訓;

            6.在你出生之前,你的父母并非像現在這樣乏味。他們變成今天這個樣子是因為這些年來他們一直在為你付賬單,給你洗衣服,聽你大談你是如何的酷;

            7.你的學校也許已經不再分優等生和劣等生,但生活卻仍在作出類似區分;

            8.生活不分學期,你并沒有暑假可以休息,也沒有幾個人樂于幫你發現自我;

            9.電視并不是真實的生活,在現實生活中,人們實際上得離開咖啡屋去干自己的工作;

            10.善待乏味的人,有可能到頭來會為一個乏味的人工作。

          posted @ 2005-11-16 10:16 qiyadeng 閱讀(301) | 評論 (0)編輯 收藏

          搞定了SCWCD!考試的題目好像大部分都沒有見過,但是有的題式TestKing的原題,還是比較驚險,考試的時候越來越不自信,因為這段時間比較忙,我沒怎么花時間復習。

          還好,最后還是過了,73%,我還是比較滿意,因為我做了4,5套題有些及格有些不及格,及格的也不超過70分,可能是真題比較簡單(好像不簡單^_^),也可能我運氣比較好。

             Custom Tag Library考的很深,EL也是考試的一個重點。還要JSP Standard Actions也比較突出。要考的同志要注意下。

          posted @ 2005-11-06 20:38 qiyadeng 閱讀(364) | 評論 (0)編輯 收藏

          中文的Java API
          http://gceclub.sun.com.cn/download/Java_Docs/html/zh_CN/api/index.html

          posted @ 2005-11-03 22:15 qiyadeng 閱讀(326) | 評論 (0)編輯 收藏

          該死的!不得不讓我說臟話了!莫名其妙的問題。
          現在算是比較清楚了。最近正在做一個分布式的系統的整合。中心數據庫用的utf8的編碼,以前的老的系統用的是latin1的編碼。
          在latin1的編碼中插入和查詢數據:
          不用在連接字符上花功夫。
          只要下面這個類,把中文轉換為latin1的編碼,因為默認的連接是lanti1的所以還要另外的連接字符串嗎?

           1/*
           2 * Created on 2005-8-15
           3 *
           4 * TODO To change the template for this generated file go to
           5 * Window - Preferences - Java - Code Style - Code Templates
           6 */

           7package com.motel168.util;
           8
           9/**
          10 * @author qiya
          11 * 
          12 * TODO To change the template for this generated type comment go to Window -
          13 * Preferences - Java - Code Style - Code Templates
          14 */

          15public class Chinese {
          16    public static String toChinese(String iso)
          17        String gb; 
          18        try
          19            if(iso.equals(""|| iso == null)
          20                return ""
          21            }
           
          22            else
          23                iso = iso.trim(); 
          24                gb = new String(iso.getBytes("ISO-8859-1"),"GB2312"); 
          25                return gb; 
          26            }
           
          27        }
          catch(Exception e)
          28            System.err.print("編碼轉換錯誤:"+e.getMessage()); 
          29            return ""
          30        }

          31    }

          32    public static String toLatin(String iso)
          33        String gb; 
          34        try
          35            if(iso.equals(""|| iso == null)
          36                return ""
          37            }
           
          38            else
          39                iso = iso.trim(); 
          40                gb = new String(iso.getBytes("GB2312"),"ISO-8859-1"); 
          41                return gb; 
          42            }
           
          43        }
          catch(Exception e)
          44            System.err.print("編碼轉換錯誤:"+e.getMessage()); 
          45            return ""
          46        }

          47    }

          48
          49}

          50

          在utf8編碼的那一段更簡單,所有的編碼設為utf8。
          上次mysql中文問題提到過,就不再提了。
          另外使用hibernate的時候,也會出現一些中文問題,這時候需要進行如下設置:
          在hibernate.cfg.xml的配置文件中加入:
          <property name="connection.characterEncoding">UTF-8</property>
          同樣不需要在連接字符串上加入參數。
          然后使用Filter:
          在web.xml中加入如下信息:
              <filter>
                  <filter-name>filter-name</filter-name>
                  <filter-class>com.motel168.util.SetEncodeFilter</filter-class>
                  <init-param>
                      <param-name>defaultencoding</param-name>
                      <param-value>UTF-8</param-value>
                  </init-param>
              </filter>
              <filter-mapping>
                  <filter-name>filter-name</filter-name>
                  <url-pattern>/*</url-pattern>
              </filter-mapping>
          對應的類為:
          package com.motel168.util;

          import java.io.IOException;

          import javax.servlet.Filter;
          import javax.servlet.FilterChain;
          import javax.servlet.FilterConfig;
          import javax.servlet.ServletException;
          import javax.servlet.ServletRequest;
          import javax.servlet.ServletResponse;

          public class SetEncodeFilter implements Filter {

              protected FilterConfig filterConfig = null;

              protected String defaultEncoding = null;

              public void init(FilterConfig arg0) throws ServletException {
                  this.filterConfig = arg0;
                  this.defaultEncoding = filterConfig.getInitParameter("defaultencoding");

              }

              public void doFilter(ServletRequest request, ServletResponse response,
                      FilterChain chain) throws IOException, ServletException {

                  request.setCharacterEncoding(selectEncoding(request));
                  chain.doFilter(request, response);

              }

              public void destroy() {
                  this.defaultEncoding = null;
                  this.filterConfig = null;

              }

              protected String selectEncoding(ServletRequest request) {
                  return this.defaultEncoding;
              }

          }


          posted @ 2005-10-20 16:12 qiyadeng 閱讀(620) | 評論 (0)編輯 收藏

          簡單標簽初始化過程:
          START tag handler instance created --> setJspContext is called --> setter for attribute is called
          --> setJspBody is called --> doTag is called
          -->END

          HttpServletResponse.sendRedirect() 之后保持session(不支持cookies)
          By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method


          There are only 3: page, taglib and include.

          The HttpSessionAttributeListener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application.

          The HttpSessionBindingListener interface causes an object to be notified when it is bound to or unbound from a session.

          The HttpSessionListener interface notifies any changes to the list of active sessions in a web application

          The HttpSessionActivationListener interface notifies objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated.

          The ServletContextAttributeListener interface receive notifications of changes to the attribute list on the servlet context of a web application

          Java code in the scriptlet is validated during the compilation phase of the servlet life-cycle.

          During the page translation phase of a JSP page life-cycle, the JSP page is parsed and a Java file containing the corresponding servlet is created. The servlet created will contain the declared jspInit() overriding the default jspInit() method which is declared in a vendor-specific JSP page base class.

          JSP declaration tag can contain an uninitialised variable declaration.

          authentication techniques that are based on builtin mechanisms of HTTP:BASCI ,DIGEST

          The following is the sequence of things that happen when you invalidate a session:
          1. Container calls sessionDestroyed() on all HttpSessionListeners configured in web.xml (in the order they are declared in web.xml). Notice that although the method name is sessionDestroyed, the session is not destroyed yet. It is about to be destroyed.
          2. The container destroys the session.
          3. The container calls valueUnbound() on all the session attributes that implement HttpSessionBindingListner interface.

          <security-constraint>
             <web-resource-collection>
              <web-resource-name>SalesInfo
              <url-pattern>/salesinfo/*
              <http-method>GET 
                          //可以0到多個,當0個時,代表外界沒有人可以用http的方法存取設限的資料(其餘方法如forward,include可被內部程式叫用)
             
             <auth-constraint>
              <role-name>manager    
                          //可以0到多個或是設成"*",當設成"*"時所有人都可以存取,當設成,沒有人可以存取
             
             <user-data-constraint>
              <transport-guarantee>NONE/CONFIDENTIAL/INTEGRAL
                          //
          NONE implies HTTP;CONFIDENTIAL,INTEGRAL imply HTTPS
             

          Only the following directives are valid for tag files:
          taglib, include, tag, attribute, variable.

          The following are the implicit objects availble to EL in a JSP page:
          . pageContext - the PageContext object
          . pageScope - a Map that maps page-scoped attribute names to their values
          . requestScope - a Map that maps request-scoped attribute names to their values
          . sessionScope - a Map that maps session-scoped attribute names to their values
          . applicationScope - a Map that maps application-scoped attribute names to
          their values
          . param - a Map that maps parameter names to a single String parameter value (obtained by calling ServletRequest.getParameter(String name))
          . paramValues - a Map that maps parameter names to a String[] of all values for that parameter (obtained by calling ServletRequest.getParameterValues(String name))
          . header - a Map that maps header names to a single String header value (obtained by calling ServletRequest.getHeader(String name))
          . headerValues - a Map that maps header names to a String[] of all values for that header (obtained by calling ServletRequest.getHeaders(String))
          . cookie - a Map that maps cookie names to a single Cookie object. Cookies are retrieved according to the semantics of HttpServletRequest.getCookies(). If the same name is shared by multiple cookies, an implementation must use the first one encountered in the array of Cookie objects returned by the getCookies() method. However, users of the cookie implicit object must be aware that the ordering of cookies is currently unspecified in the servlet specification.
          . initParam - a Map that maps context initialization parameter names to their String parameter value (obtained by calling  ServletContext.getInitParameter( String name))

          It is very important that you understand what methods of the following interfaces are invoked in which situation.
          HttpSessionActivationListener: Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. NOT configured in web.xml.
          HttpSessionAttributeListener: This listener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application. Configured in web.xml.
          HttpSessionBindingListener: Causes an object to be notified when it is bound to or unbound from a session. NOT configured in web.xml.
          HttpSessionListener: Implementations of this interface are notified of changes to the list of active sessions in a web application. Configured in web.xml.

          isRequestedSessionIdFromCookie method checks whether the requested session id came in as cookie

          getAuthType() method of HttpServletRequest returns name of the authenticating scheme used to protect the servlet

          posted @ 2005-10-19 21:57 qiyadeng 閱讀(427) | 評論 (0)編輯 收藏

          僅列出標題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 
          主站蜘蛛池模板: 崇左市| 蛟河市| 砚山县| 高台县| 陕西省| 墨玉县| 仁化县| 永和县| 阳原县| 栾川县| 元氏县| 包头市| 松溪县| 道孚县| 会东县| 公主岭市| 新丰县| 芦山县| 石柱| 陇南市| 乌鲁木齐市| 垣曲县| 汾西县| 吕梁市| 清水县| 嘉义县| 明光市| 葫芦岛市| 太仆寺旗| 台南县| 内乡县| 黄石市| 枣阳市| 延安市| 苍梧县| 长岭县| 广东省| 阿拉善左旗| 监利县| 剑川县| 郯城县|