posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

IE的URI的提交是有压缩的(google好象有)所以utf-8对ie 不太好用我们为了方便ie统一gbk
   1.Tomcat 的 server.xml 的 Connector 中加入 URIEncoding="GBK"
   2.  server 类中加入
        rpo.setCharacterEncoding("GBK");
        req.setCharacterEncoding("GBK");
        rpo.setContentType("text/html; charset=GBK");

   3.jsp 页面加入
        <%@ page pageEncoding="GBK"%>
        <%@ page contentType="text/html; charset=GBK" %>
 
IE乱码问题解决.如果还没解决那就@#$%......


FF的uri 好象默认是UTF-8 所以用 GBK就不方便了 就同上面的 改 UTF-8 就可以了


FF 和 IE 一起方便使用的我还没找到 .

例代码
 var url = "/json/json?jsonStr="+ (new fun()).toJSONString() ;   //这 Ajax 就没有乱码了
         request.open(
"GET", url, true);
         request.send(
null);
        

posted @ 2007-09-13 10:23 G_G 阅读(2014) | 评论 (6)编辑 收藏

引用 dojo demo  但在IE上总是有问题. 不显示 @#$!*& 郁闷了我一天 ,后来发现 

        <script type="text/javascript">
                dojo.require(
"dijit.layout.LayoutContainer");  //位置和官方的反过来 IE 就没事了 @#$%^!
                dojo.require(
"dijit.layout.ContentPane");   // FF没这问题  .还是FF好啊 大家支持FF   ^_^
     
</script>

<html>
<head>
<title>Layout Container Demo 1</title>
    
<style type="text/css">
        @import "/dojoCharset/js/dojo/dijit/themes/tundra/tundra.css";
        @import "/dojoCharset/js/dojo/dojo/dojo.css"
    
</style>
        
<script type="text/javascript" src="/dojoCharset/js/dojo/dojo/dojo.js"
                djConfig
="parseOnLoad: true"></script>
        
<script type="text/javascript" src="/dojoCharset/js/create/cr.js"
                djConfig
="parseOnLoad: true"></script>        
        
<script type="text/javascript">
                dojo.require(
"dijit.layout.LayoutContainer");
                dojo.require(
"dijit.layout.ContentPane");
     
</script>
</head>
<body class="tundra">

<div dojoType="dijit.layout.LayoutContainer" style="width: 100%; height: 100%">    //开一个 LayOut 空间
   
<div dojoType="dijit.layout.ContentPane" layoutAlign="top" style="background-color:red" href="/dojoCharset/html/top.jsp"> //top
        The Dojo Book
   
</div>
   
<div  dojoType="dijit.layout.ContentPane" layoutAlign="left"  //left
        style
="background-color:lightblue;width: 120px;">
        Table of Contents
    
</div>
    
<div id='div' dojoType="dijit.layout.ContentPane" layoutAlign="client"         //client
        style
="background-color:yellow">
            
<blockquote><href="../node/717">Introduction</a>
                
<ol>
                    
<li><href="../node/718">Dojo: What is It?</a></li>
                    
<li><href="../node/719">History</a></li>
                    
<li><href="../node/733">What Dojo Gives You</a></li>
                
</ol>
                
</blockquote>
    
</div>
</div>       
</body></html>

cr.js
    function on(){
       
function helloPressed(){
               window.alert('ok');
            dojo.xhrGet(
{
                url: '
/dojoCharset/html/top.jsp', 
                handleAs: 
"text",
                encoding: 
"utf-8",
                timeout: 
5000// Time in milliseconds
                load: function(data, ioArgs) {
                    document.getElementById('div').innerHTML 
= data ;
                }

            }
);
        }

              dojo.addOnLoad(helloPressed);         
         
    }

top.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page contentType="text/html;charset=gb2312" %> 
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">  
        
<script type="text/javascript"
            src
="/dojoCharset/js/create/cr.js"></script> 
    
</head>
    
<body>
        
<center>
            
<h3>
                
<font color='darkcyan'>
                    大家好
                
</font>
                
<INPUT id='butt' value="list" type="button" onclick="on()"/>
            
</h3>
        
</center>
    
</body>
    
</html>

posted @ 2007-09-07 11:19 G_G 阅读(643) | 评论 (0)编辑 收藏

页面 的 LayOut 用: LayoutContainer 
   这里有个问题 html -> html  的乱码问题不是很好解决(可能是dojo 0.9 bug??) 这 top , left .... 等可以用 .jsp来做 再用dojoLayout加入主页面 .html

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd"
>
< html >
< head >
< title > Layout Container Demo 1 </ title >
    
< style  type ="text/css" >
        @import "http://127.0.0.1:7000/dojoCharset/js/dojo/dijit/themes/tundra/tundra.css";
        @import "http://127.0.0.1:7000/dojoCharset/js/dojo/dojo/dojo.css"
    
</ style >
        
< script  type ="text/javascript"  src ="http://127.0.0.1:7000/dojoCharset/js/dojo/dojo/dojo.js"
                djConfig
="parseOnLoad: true" ></ script >
        
< script  type ="text/javascript" >
                dojo.require(
" dijit.layout.ContentPane " );
                dojo.require(
" dijit.layout.LayoutContainer " );
     
</ script >
</ head >
< body  class ="tundra" >

< div  dojoType ="dijit.layout.LayoutContainer"  style ="width: 100%; height: 100%" >
   //这里 href 是关键到入 top.jsp 还没乱码问题 
   
< div  dojoType ="dijit.layout.ContentPane"  layoutAlign ="top"  style ="background-color:red"  href ="http://127.0.0.1:7000/dojoCharset/html/top.jsp" >
   
</ div >
   
< div  dojoType ="dijit.layout.ContentPane"  layoutAlign ="left"
        style
="background-color:lightblue;width: 120px;" >
    
</ div >
    
< div  dojoType ="dijit.layout.ContentPane"  layoutAlign ="client"
        style
="background-color:yellow" >
     </ div >
</ div >        
</ body ></ html >

或者用 一种比较复杂但灵活的方法
<html>
  
<head>  
    
<title>Dojo: Hello World!</title>
    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    

    
<!-- SECTION 1 -->
  
<script type="text/javascript"
    src
="http://127.0.0.1:7000/dojoCharset/js/dojo/dojo/dojo.js"></script> 
    
<!-- SECTION 2 -->
    
<script type="text/javascript">
      
function helloPressed()
      {
        dojo.xhrGet({
                       url: 'http:
//127.0.0.1:7000/dojoCharset/dojo', 
                       handleAs: "text",
                       encoding: 
"utf-8",
                       timeout: 
5000// Time in milliseconds
                       load: function(data, ioArgs) {
                              window.alert(data);  
// Prints "peach"
                               document.getElementById('div').innerHTML = data ;
                               // div 添加
                       }
                    });
      }
    dojo.addOnLoad(helloPressed);
    
</script>
    
<div id='div' />
</html>

posted @ 2007-09-06 17:52 G_G 阅读(520) | 评论 (0)编辑 收藏

1.ArrayList
    
<script type="text/javascript">

dojo.require(
"dojox.collections.ArrayList");

dojo.addOnLoad(
function(){
    
var a = ['a1','a2'];
    
var arr = new dojox.collections.ArrayList(a); 
    arr.add('xx1');
    arr.add('xx2');
    arr.add('xx3');
    
    //迭带
    
var it = arr.getIterator();
    
while(!it.atEnd()){
        document.writeln( it.get());
    }
    
   //数量
    document.writeln(arr.count);
    
    //删除
    arr.remove('xx1');
    
    
var arr_str = arr.toString()
    document.writeln( arr_str );
});

</script>

与java的collections 很相同方法就不一一介绍了
addRange --add 集合
clear , clone , contains , indexOf , insert ,
item  -- get(i),
removeAt(i),
reverse ???,
sort,
toArray . return  object[]

posted @ 2007-09-05 16:06 G_G 阅读(281) | 评论 (0)编辑 收藏

1.画图
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd" >
< html >
    
< head >
        
< meta  http-equiv ="Content-Type"  content ="text/html"   />
        
< script  type ="text/javascript"  src ="http://127.0.0.1:8000/lib/dojo/dojo_0.9/dojo/dojo.js"
                djConfig
="parseOnLoad: true" ></ script >
    
< style  type ="text/css" >
        @import "http://127.0.0.1:8000/lib/dojo/dojo_0.9/dojo/resources/dojo.css";
        @import "http://127.0.0.1:8000/lib/dojo/dojo_0.9/dijit/tests/css/dijitTests.css";
    
</ style >     
< script  type ="text/javascript" >
dojo.require(
" dojox.gfx " );
dojo.addOnLoad(
function (){
    container 
=  dojo.byId( " gfx_holder " );
    
var  surface  =  dojox.gfx.createSurface(container,  385 385 );         // 创建图范围
    surface.createImage({width:  30 , height:  40 , src:  " http://127.0.0.1:8000/images/tomcat.ico " });   // create 

    surface.createCircle({cx:  100 , cy:  100 , r:  20 }) .setFill('blue');
    
    surface.createLine({x1: 
0 , y1:  350 , x2:  700 , y2:  250 }).setStroke( " green " );
    
    surface.createRect({x: 
70 , y:  70 , width:  20 , height:  20 }).setFill( " red " );
    
    
var  hour_hand_points  =  [{x:  50 , y:  82 }, {x:  100 , y:  15 },{x:  200 , y:  20 }];
    surface.createPolyline(hour_hand_points).setFill('aqua');
    
    
    
var  m  =  dojox.gfx.matrix;
    
var  initial_matrix  =  m.translate( 250 250 );
    g 
=  surface.createGroup().setTransform(initial_matrix);
    
var  f, s  =  {color:  " black " , width:  1 };
    f 
=   " #ffffff " ; s  =  {color:  " #000000 " , width:  0.172 };
    g.createPath(
" M-122.304 84.285C-122.304 2000.285 -122.203 86.179 -123.027 86.16C-123.851 700.141 -140.305 38.066 -160.833 40.309C-160.833 40.309 -143.05 32.956 -122.304 84.285z " ).setFill(f).setStroke(s);
    //画画 不过天知道画的是什么
    
});
</ script >
< div  id ="gfx_holder"  style ="width: 385px; height: 385px;" ></ div >

</ html >
  case dojox.gfx.defaultPath.type:  return this.createPath(shape);
  case dojox.gfx.defaultRect.type:  return this.createRect(shape);
  case dojox.gfx.defaultCircle.type:  return this.createCircle(shape);
  case dojox.gfx.defaultEllipse.type:  return this.createEllipse(shape);
  case dojox.gfx.defaultLine.type:  return this.createLine(shape);
  case dojox.gfx.defaultPolyline.type: return this.createPolyline(shape);
  case dojox.gfx.defaultImage.type:  return this.createImage(shape);
  case dojox.gfx.defaultText.type:  return this.createText(shape);
  case dojox.gfx.defaultTextPath.type: return this.createTextPath(shape);
可以create的 方法


2.图象拖动事件
               -----正方形--------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html" />
        
<script type="text/javascript" src="http://127.0.0.1:8000/lib/dojo/dojo_0.9/dojo/dojo.js"
                djConfig
="parseOnLoad: true"></script>
    
<style type="text/css">
        @import "http://127.0.0.1:8000/lib/dojo/dojo_0.9/dojo/resources/dojo.css";
        @import "http://127.0.0.1:8000/lib/dojo/dojo_0.9/dijit/tests/css/dijitTests.css";
    
</style>    
<script type="text/javascript">

dojo.require(
"dojox.gfx");

var container = null;
var container_position = null;
var surface = null;
var surface_size = null;


var gShapes = {}
var gShapeCounter = 0;

function makeCircleGrid(aShape)
{
        
var id = "shape_" + (gShapeCounter++);
        aShape.getEventSource().setAttribute('shapeid', id);
        dojox.gfx._addClass(aShape.getEventSource(), 
"movable");
        gShapes[id] 
= aShape;
    
}

var current_shape = null;
var current_shape_window = null;
var last_position = null;

function getShape(event)
{
    
var id = event.target.getAttribute('shapeid');
    
var s  = id ? gShapes[id] : null;
    
return s;
}

function handleMouseDown(event)
{
    
var shape = getShape(event);
    
if (shape) {
        current_shape 
= shape;
        last_position 
= {
            x: event.clientX 
- container_position.x,
            y: event.clientY 
- container_position.y
        };
        
        
var params = shape.getShape();
         //正方形的是 params [x ,y width,height]
        
var center = dojox.gfx.matrix.multiplyPoint(shape.getTransform(), params.x, params.y);
        
var dx = last_position.x - center.x;
        
var dy = last_position.y - center.y;

        current_shape_window 
= {
            x1: params.width 
+ dx,
            y1: params.height 
+ dy,
            x2: surface_size.width    
+ dx,
            y2: surface_size.height  
+ dy
        };
    }
    dojo.stopEvent(event);
}

function handleMouseMove(event)
{
    
if(!current_shape) return;
    
var x = Math.min(Math.max(event.clientX - container_position.x, current_shape_window.x1), current_shape_window.x2);
    
var y = Math.min(Math.max(event.clientY - container_position.y, current_shape_window.y1), current_shape_window.y2);
    current_shape.applyTransform({dx: x 
- last_position.x, dy: y - last_position.y});
    last_position 
= {x: x, y: y};
    dojo.stopEvent(event);
}

function handleMouseUp(event)
{
    current_shape 
= null;
    dojo.stopEvent(event);
}

function initGfx() {
    container 
= dojo.byId("gfx_holder");
    container_position 
= dojo.coords(container, true);
    surface 
= dojox.gfx.createSurface(container, 500500);
    surface_size 
= surface.getDimensions();
    surface_size.width  
= parseInt(surface_size.width);
    surface_size.height 
= parseInt(surface_size.height);


    
var aShape = surface.createRect({x: 70, y: 70, width: 20, height: 20}).setFill("red");

    makeCircleGrid(aShape);

    dojo.connect(container, 'onmousedown', handleMouseDown);
    dojo.connect(container, 'onmousemove', handleMouseMove);
    dojo.connect(container, 'onmouseup',   handleMouseUp);
    
    
// cancel text selection and text dragging
    dojo.connect(container, "ondragstart",   dojo, "stopEvent");
    dojo.connect(container, 
"onselectstart", dojo, "stopEvent");
}

dojo.addOnLoad(initGfx);

</script>

<style type="text/css">
.movable 
{ cursor: pointer; }
</style>

</head>
<body>
    
<h1>dojox.gfx: 100 draggable circles</h1>
    
<div id="gfx_holder" style="width: 500px; height: 500px;"></div>
</body>
</html>

          --------圆是-----------

function handleMouseDown(event)
{
    
var shape = getShape(event);
    
if (shape) {
        current_shape 
= shape;
        last_position 
= {
            x: event.clientX 
- container_position.x,
            y: event.clientY 
- container_position.y
        };
        
var params = shape.getShape();
         
      // 形状的不同 就是 params 的取值不同 params [cx,xy,r]
        
var center = dojox.gfx.matrix.multiplyPoint(shape.getTransform(), params.cx, params.cy);
        
var dx = last_position.x - center.x;
        
var dy = last_position.y - center.y;
        
var r  = params.r;
        current_shape_window 
= {
            x1: r 
+ dx,
            y1: r 
+ dy,
            x2: surface_size.width  
- r + dx,
            y2: surface_size.height 
- r + dy
        };
    }
    dojo.stopEvent(event);
}

其他不用再说了吧!!

 

 

posted @ 2007-09-05 15:21 G_G 阅读(1415) | 评论 (0)编辑 收藏

dojo0.9 一个完整的开发javascript包非常值得去学习。
有用的地方就不用多说了.....
开始学习吧

基础:
1. dojo.declare  javascript类方便使用(继承,创造等等)
    <1>简单创造,使用
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html" />
        
<script type="text/javascript" src="http://127.0.0.1:8000/lib/dojo/dojo_0.9/dojo/dojo.js"
                djConfig
="parseOnLoad: true"></script>
    
</head>
    
<body>
    
</body>
</html>
<script type="text/javascript">
    dojo.declare(
"DojoClass",null,{
        prptId: 'foo',
        method:
function(val){
            window.alert(val);
        }
    });
    
    
var obj = new DojoClass();
    obj.method('XX');              //效果 alert('XX')
</script>
    <2>简单继承
<script type="text/javascript">
    dojo.declare(
"DojoClass",null,{
        prptId: 'foo',
        method:
function(val){
            window.alert(val);
        }
    });
    
    dojo.declare(
"Class",DojoClass,{
        prptId2:'
2222',
        method2:
function(val){
            window.alert(
"!!!"+val);
        }
    });
    
var obj = new Class();
    obj.method('XX');         //效果 alert('XX');
    obj.method2( obj.prptId
+obj.prptId2 ); //效果 alert( '!!!foo2222' );
    
</script>
    <3>继承重写
<script type="text/javascript">
    dojo.declare(
"DojoClass",null,{
        prptId: 'foo',
        method:
function(val){
            window.alert(val);
        }
    });
    
    dojo.declare(
"Class",DojoClass,{
        prptId2:'
2222',
        method:
function(val){
            val 
= val+'list';
            
this.inherited('method',arguments);
        },
        method2:
function(val){
            window.alert(
"!!!"+val);
        }
    });
    
var obj = new Class();
    obj.method('XX');  //效果 alert( 'XXlist' );
    
    
</script>
<4> initializer 类构造
   没成功 ?? 原因不明
<script type="text/javascript">
    dojo.declare(
"DojoClass",null,{

        initializer:
function(val){
            
this.prptId=val;
        },
        
        prptId: 'foo',
        
        method:
function(val){
            window.alert(val);
        }
    });
    
    
var obj = new DojoClass('liukaiyi');
    obj.method( obj.prptId );  //效果 alert('foo'); 没成功
</script>



posted @ 2007-09-05 10:27 G_G 阅读(1022) | 评论 (3)编辑 收藏

    1。文件的映射。由于使用 MyEclipse(傻瓜版^_^) 所以 hibernate工具(extensions,Middlegen,tools等)一直没好好研究这就不献丑了。
    2。Criteria
       1)查询条件通过 Criteria.add 添加 Expression 用于描述条件
                Expression.( and or like in le lt ..... )
                参见: Criteria查询
       2)criteria.setFirstResult(100);
          criteria.setMaxResults(20); //检索范围
          criteria.addOrder(Order.asc("name")); //排序

          .add( Expression.sql("lower($alias.name) like lower(?)", "Fritz%", Hibernate.STRING)   //直接嵌入SQL
       3)
Cat cat = new Cat();
          ....

         List results = session.createCriteria(Cat.class).add( Example.create(cat) ).list(); //根据对象查询
     
    3。HQL 完全面向对象的,具备继承、多态和关联等特性。
       1)参见: HQL
       2)内连接,inner join
          左外连接,left outer join

          右外连接,right outer join
 
          http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html
          代表性的语句
     
Hql.hbm.xml
        
<set name="fkSet" inverse="true">
            
<key column="id"/>
            
<one-to-many class="Fk"/>
        
</set>
SQL
alter table fk add constraint  FK_hf foreign key(id) references hql(id)

mysql> select * from hql;
+----+----------+
| id | name     |
+----+----------+
|  0 | liukaiyi |
|  1 | heha     |
+----+----------+
2 rows in set (0.00 sec)

mysql> select * from fk;
+----+------+
| id | name |
+----+------+
|  0 | yy   |
|  1 | xx   |
+----+------+
2 rows in set (0.00 sec)


//简单的 结果: 2  liukaiyi:heha
        Query qu = se.createQuery("select h.name " +
                                        
" from Hql h , Fk f" +
                                        
" where h.id = f.id" );
        List list 
=  qu.list() ;
        tr.commit();
        System.out.println( list.size() );
        System.out.println( list.get(
0)+":"+list.get(1) );


//给出对象 结果 : heha
Query qu = se.createQuery("from Hql h where h.fkSet.name='xx'");
((Hql)list.get(
0)).getName() ;


//给出Object 结果:heha xx
Query qu = se.createQuery("select h.name,f.name from Hql h join h.fkSet f where f.name='xx'");
List list 
=  qu.list() ;
tr.commit();
System.out.println(list.size());    
Object[] objs 
= (Object[]) list.get(0) ;
System.out.println( objs[
0+":"+objs[1] );

//给出 Map  heha xx
        
        Query qu 
= se.createQuery("select new map( h.name as hn,f.name as fn)from Hql h join h.fkSet f where f.name='xx'");
        List list 
=  qu.list() ;

        tr.commit();
        System.out.println(list.size());    
        Map map 
= ((Map)list.get(0));
        System.out.println( map.get(
"hn") );
    }

//报表语句  结果: 1

        Query qu = se.createQuery("select count(*) from Hql h join h.fkSet f " +
                                        
" where h.name='heha' and h.id=f.id " +
                                        
" group by h.name ");
        List list 
=  qu.list() ;
        tr.commit();
        System.out.println( list.get(
0) );

//集合内 结果 liukaiyi:heha
//
元素集(elementsindices 函数) 可以使用 any, some, all, exists, in
//
EG:  from Player p where 3 > all elements(p.scores)
+----+----------+
| id | name     |
+----+----------+
|  0 | liukaiyi |
|  1 | heha     |
|  3 | oo       |
+----+----------+

       
        Query qu 
= se.createQuery("select h.name " +
                                        
" from Hql h" +
                                        
" where h.id in elements(h.fkSet.id) " );
        List list 
=  qu.list() ;
        tr.commit();
        System.out.println( list.get(
0)+":"+list.get(1) );


//使用 javaBean 绑定
Query q = s.createQuery("from foo Foo as foo where foo.name=:name and foo.size=:size");
q.setProperties(fooBean); 
// fooBean包含方法getName()与getSize()
List foos = q.list();












posted @ 2007-08-24 16:36 G_G 阅读(580) | 评论 (0)编辑 收藏

问题: IE,FF用 xpath 在javascript动态解读
解决: 自定义jsXpath 类

js.js
//关键是 jsXpath 类
//使用是 new 并 给属性 domx 值 DOMXml
//var nodes = obj.getPathNodes( xpath ); 就是 xpath语句如:
//beans/bean
//再 var node = obj.next( nodes )
//node 可以使用了

var dom = null ;
var jp = new jsXpath();

function load(ul){
    
new Ajax.Request(
        ul,
        {
            method: 'get',
            onComplete: action              
        });    
}

function action(req){
 
var path = " /beans/bean[string-length(@xid)<3] ";
 dom 
= req.responseXML ;
 jp.domx 
= dom ; 
 
var list =  jp.getPathNodes(path) ;
 createSelect(jp,list, document.getElementById('ii') );
//建 select ii
}

function jsXpath(){
    
this.nexti = 0 ;
    
this.domx = null ;
    
    
this.getPathNodes = function(path){
        
var val =null ;
        
if( navigator.appName.indexOf('Microsoft')== -1 ){
           val  
= document.evaluate(path,this.domx ,null,XPathResult.ANY_TYPE,null ) ;
        }
else{
            
this.domx.setProperty("SelectionLanguage","XPath");
            val 
= this.domx.documentElement.selectNodes( path ) ;
        }
        
return val ;
    }
    
    
this.next =  function(domp,ii){
        
if( navigator.appName.indexOf('Microsoft')== -1 ){
           
return domp.iterateNext() ;
        }
else{
            
if(ii!=nullthis.nexti = ii ;
            
return domp[this.nexti++];
        }
    }
}

function createSelect(xpath,doms,sele){
        
try{
            
var item=xpath.next(doms);
            
while(item){
                
var opt =document.createElement('option');
                
var text=document.createTextNode( item.firstChild.nodeValue  );
                opt.appendChild(text);
                opt.setAttribute(
"value",item.getAttribute('xid') );
                sele.appendChild(opt);
                
                item 
= xpath.next(doms);
            }
        }
catch(e){dump(e);}
}

//建 select jj 与 select ii的 selectedIndex 有关
function duSel(){
        
var sele = document.getElementById('jj');
        
var sdom = document.getElementById('ii');
        
        
var num = sele.getElementsByTagName('option').length-1
        
for(var i=num; i>0 ; i--
            sele.remove(
1); 
        
         
var skey = sdom.options[ sdom.selectedIndex ].value

         
var path = "/beans/bean[  starts-with( @xid , '"+skey+"') and string-length(@xid)>3  ]";

         
var jpp = new jsXpath();
         jpp.domx 
= dom ; 
         
var lj = jpp.getPathNodes(path);

         createSelect(jpp,lj, document.getElementById('jj') );
}

xml.xml
<?xml version="1.0" encoding="GB2312" standalone="no"?>
<beans>
    
<bean xid='01' >北京局</bean>
    
<bean xid='0101'>ftd</bean>
    
<bean xid='0102'>tsd</bean>

    
<bean xid='02'>沈阳局</bean>
    
<bean xid='0202'>sy1</bean>
    
<bean xid='0203'>sy2</bean>
    
<bean xid='0204'>sy3</bean>
</beans>

xpath.html //级连的 下拉框出来了
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        
<script language='JavaScript' src="js/js.js"></script>
        
<script language="JavaScript" src="lib/prototype/prototype.js"></script>
        
<script language='JavaScript' src='js/xpath.js'></script>
    
</head>

    
<body onload='load( "./xml/xml.xml" )'>    
        
<select id="ii" onchange='duSel();'>
             
<option value="" >--段选择--</option>
        
</select>
        
<select id="jj">
             
<option value="" >--车间选择--</option>
        
</select>
    
</body>
</html>

心得: xpath 是好东西 好东西啊

posted @ 2007-08-14 14:29 G_G 阅读(1179) | 评论 (1)编辑 收藏

问题: java 可以用 xpath ; javascriopt 也可以!
解决: document.evaluate 方法
参考:浏览器中的XPath支持
xpath.html
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        
<script language='JavaScript' src="js/js.js"></script>
        
<script language="JavaScript" src="lib/prototype/prototype.js"></script>
    
</head>
    
<body onload='load( "./xml/xml.xml" )'>    
    
</body>
</html>
// xpath.js 是一个扩展包在这里是可以统一 方法IE ,FF都可以使用 evaluate方法
// http://www.blogjava.net/Files/Good-Game/xpath.rar 下载
// 说明  http://dev.infoaccelerator.net/spryDocs/overview-summary.html

posted @ 2007-08-13 13:58 G_G 阅读(1744) | 评论 (0)编辑 收藏

get set 参考 BeanUtil 包 和 Xpath
http://commons.apache.org/  的 jxpath User's Guide

类的加载
JXPathContext context = JXPathContext.newContext( obj );
//和 xpath 的 范围确定

一般取值 存值
String fName = (String)context.getValue("firstName"); //setValue
//参考 http://www.blogjava.net/Good-Game/archive/2007/08/10/135739.html

一般的统计和使用 c 为 list [id,name,.....]

        JXPathContext context = JXPathContext.newContext(c);
        System.out.println( context.getValue(
"count( .[name='oo' and id='1' ] )") ); //对象 name=oo 和 id=1的有多少个
System.out.println( context.getValue("sum( .[name='oo' and id='1' ]/id )") );//对象name=oo和id=1的所有id相加





得到集合
 Iterator threeBooks = context.iterate("books[position() < 4]");
//xpath 的位置函数 position 其他函数参考 http://www.w3.org/TR/xpath
//4 Core Function Library

xpath 使用
public class Employee {
    
private Map addressMap = new HashMap();
    {
        addressMap.put(
"home"new Address());
        addressMap.put(
"office"new Address());
    }
    
public Map getAddresses(){
       
return addressMap;
    }
    
 }
 String homeZipCode 
= (String)context. getValue("addresses[@name='home']/zipCode");
//使用的是 addressMap map 的 key = home 的Address类属性的 zipCode

xml 在程序 与 xpath 的切入点
    <?xml version="1.0" ?>
    
<vendor>
      
<location id="store101">
        
<address>
          
<street>Orchard Road</street>
        
</address>
      
</location>

      
<location id="store102">
        
<address>
          
<street>Tangerine Drive</street>
        
</address>
      
</location>
    
</vendor>

class Company {
    
private Container locations = null;

    
public Container getLocations(){
        
if (locations == null){
            URL url 
= getClass().getResource("Vendor.xml");
            locations 
= new XMLDocumentContainer(url);
        }
        
return locations;
    }
 }
 
 context 
= JXPathContext.newContext(new Company());
 
 String street 
= (String)context.getValue(
                
"locations/vendor/location[@id = 'store102']//street");
// 类Container的 属性 locations 头 vendor(xml内) .....

建立 Path工厂 就是 自定义字符串 得到 自定义类
 public class AddressFactory extends AbstractFactory {
    
public boolean createObject(JXPathContext context, Pointer pointer,
                                Object parent, String name, 
int index){
     
if ((parent instanceof Employee) && name.equals("address"){
       ((Employee)parent).setAddress(
new Address());
       
return true;
     }
     
return false;
   }
 }

 JXPathContext context 
= JXPathContext.newContext(emp);
 context.setFactory(
new AddressFactory());
 context.createPath(
"address");
 context.createPathAndSetValue(
"address/zipCode""90190");
// emp 类就是 createObject方法中的 Object
//运行解析到 address字符 就进入 if中


建立内参
 JXPathContext context = JXPathContext.newContext(auth);
 context.getVariables().declareVariable(
"index"new Integer(2));
 context.setValue("$index", new Integer(3));
 Book secondBook = (Book)context.getValue("books[$index]");
// $index 为 3

确定范围
Pointer 
JXPathContext context = JXPathContext.newContext(bean);
 Pointer addressPtr 
= context.getPointer("/employees[1]/addresses[2]");
 JXPathContext relativeContext 
= 
              context.getRelativeContext(addressPtr);

 String zipCode = (String)relativeContext.getValue("zipCode");
//可以用 xpath 确定范围 很好 呵呵


方法的联系应用
 public class Formats {
    
public static String date(Date d, String pattern){
        
return new SimpleDateFormat(pattern).format(d);
    }
    
 }                                                     
 context.setFunctions(
new ClassFunctions(Formats.class"format"));
//方法的设置 format
 
 context.getVariables().declareVariable(
"today"new Date());
 String today 
=
     (String)context.getValue(
"format:date($today, 'MM/dd/yyyy')");


心得: 代码可以写成什么样呢~~ (JXpath)

posted @ 2007-08-13 10:58 G_G 阅读(2176) | 评论 (1)编辑 收藏

仅列出标题
共16页: First 上一页 8 9 10 11 12 13 14 15 16 下一页