qiyadeng

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

Denny 丹尼
1.Denny这个名字让人联想到课堂上的笑蛋-爱玩友善极度幽默的年轻男孩,脑袋却不太灵光。
2.邓是我本姓

posted @ 2006-01-04 23:13 qiyadeng 阅读(253) | 评论 (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 阅读(1001) | 评论 (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 阅读(2393) | 评论 (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 阅读(290) | 评论 (0)编辑 收藏


我的性格,不知道准不准确。测试
test.jpg

posted @ 2005-11-27 09:45 qiyadeng 阅读(476) | 评论 (2)编辑 收藏

      1.生活是不公平的,要去适应它;

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

  3.高中刚毕业你不会成为一个公司的副总裁,直到你将此职位挣到手;

 
  4.如果你认为你的老师严厉,等你当了老板再这样想;

  5.如果你陷入困境,不要尖声抱怨错误,要从中吸取教训;

  6.在你出生之前,你的父母并非像现在这样乏味。他们变成今天这个样子是因为这些年来他们一直在为你付账单,给你洗衣服,听你大谈你是如何的酷;

  7.你的学校也许已经不再分优等生和劣等生,但生活却仍在作出类似区分;

  8.生活不分学期,你并没有暑假可以休息,也没有几个人乐于帮你发现自我;

  9.电视并不是真实的生活,在现实生活中,人们实际上得离开咖啡屋去干自己的工作;

  10.善待乏味的人,有可能到头来会为一个乏味的人工作。

posted @ 2005-11-16 10:16 qiyadeng 阅读(298) | 评论 (0)编辑 收藏

搞定了SCWCD!考试的题目好像大部分都没有见过,但是有的题式TestKing的原题,还是比较惊险,考试的时候越来越不自信,因为这段时间比较忙,我没怎么花时间复习。

还好,最后还是过了,73%,我还是比较满意,因为我做了4,5套题有些及格有些不及格,及格的也不超过70分,可能是真题比较简单(好像不简单^_^),也可能我运气比较好。

   Custom Tag Library考的很深,EL也是考试的一个重点。还要JSP Standard Actions也比较突出。要考的同志要注意下。

posted @ 2005-11-06 20:38 qiyadeng 阅读(357) | 评论 (0)编辑 收藏

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

posted @ 2005-11-03 22:15 qiyadeng 阅读(324) | 评论 (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 阅读(616) | 评论 (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 阅读(425) | 评论 (0)编辑 收藏

仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页