|
IE的URI的提交是有壓縮的(google好象有)所以utf-8對ie 不太好用我們?yōu)榱朔奖鉯e統(tǒng)一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 好象默認(rèn)是UTF-8 所以用 GBK就不方便了 就同上面的 改 UTF-8 就可以了 FF 和 IE 一起方便使用的我還沒找到 . 例代碼 ?var?url?=?"/json/json?jsonStr="+?(new?fun()).toJSONString()?;?? //這 Ajax?就沒有亂碼了
?????????request.open("GET",?url,?true);
?????????request.send(null);
????????
頁面 的 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 是關(guān)鍵到入 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
>
或者用 一種比較復(fù)雜但靈活的方法 <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>
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()); ????} ???? ???//數(shù)量 ????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[]
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
);????????
//
創(chuàng)建圖范圍
????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,?500,?500); ????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); } 其他不用再說了吧!! ? ?
dojo0.9 一個完整的開發(fā)javascript包非常值得去學(xué)習(xí)。 有用的地方就不用多說了..... 開始學(xué)習(xí)吧 !基礎(chǔ):1. dojo.declare? javascript類方便使用(繼承,創(chuàng)造等等)??? <1>簡單創(chuàng)造,使用<!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 類構(gòu)造 ???沒成功 ?? 原因不明
<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>
??? 1。文件的映射。由于使用 MyEclipse(傻瓜版^_^) 所以 hibernate工具(extensions,Middlegen,tools等)一直沒好好研究這就不獻(xiàn)丑了。 ??? 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(); //根據(jù)對象查詢??? ? ??? 3。HQL 完全面向?qū)ο蟮模邆淅^承、多態(tài)和關(guān)聯(lián)等特性。 ??? ?? 1)參見: HQL??? ?? 2)內(nèi)連接,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)
//簡單的 結(jié)果: 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)?); //給出對象 結(jié)果 : hehaQuery?qu?=?se.createQuery("from?Hql?h?where?h.fkSet.name='xx'"); ((Hql)list.get(0)).getName()?;
//給出Object 結(jié)果:heha xxQuery?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")?); ????} //報表語句? 結(jié)果: 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)?); //集合內(nèi) 結(jié)果 liukaiyi:heha //元素集(elements與indices 函數(shù)) 可以使用 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();
問題:
IE,FF用 xpath 在javascript動態(tài)解讀 解決: 自定義jsXpath 類  js.js //關(guān)鍵是 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!=null)?this.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 有關(guān) 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 是好東西 好東西啊
問題:
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 是一個擴(kuò)展包在這里是可以統(tǒng)一 方法IE ,F(xiàn)F都可以使用 evaluate方法 // http://www.tkk7.com/Files/Good-Game/xpath.rar 下載 // 說明? http://dev.infoaccelerator.net/spryDocs/overview-summary.html
get set 參考 BeanUtil 包 和 Xpath http://commons.apache.org/? 的 jxpath
類的加載 JXPathContext?context?=?JXPathContext.newContext( obj ); //和 xpath 的 范圍確定
一般取值 存值
String?fName?=?(String)context.getValue("firstName"); //setValue //參考 http://www.tkk7.com/Good-Game/archive/2007/08/10/135739.html
一般的統(tǒng)計和使用 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 的位置函數(shù) position 其他函數(shù)參考 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 的切入點(diǎn)
????<?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內(nèi)) ..... 建立 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 //運(yùn)行解析到 address字符 就進(jìn)入 if中
建立內(nèi)參
?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 確定范圍 很好 呵呵
方法的聯(lián)系應(yīng)用
?public?class?Formats?{ ????public?static?String?date(Date?d,?String?pattern){ ????????return?new?SimpleDateFormat(pattern).format(d); ????} ???? ?}??????????????????????????????????????????????????? ? ?context.setFunctions(new?ClassFunctions(Formats.class,?"format")); //方法的設(shè)置 format ? ?context.getVariables().declareVariable("today",?new?Date()); ?String?today?= ?????(String)context.getValue("format:date($today,?'MM/dd/yyyy')");
心得: 代碼可以寫成什么樣呢~~ (JXpath)
|