??xml version="1.0" encoding="utf-8" standalone="yes"?>
PSQ另外,早在2006q的一资?忘记原址?sorry)Q已指出是用FileOutputStrem和FileInputStream输入输出的字节数不一致造成的,不过解决Ҏ(gu)使用的是用ByteArrayInputStream来进行读取,NByteArrayInputStream能够用不到的byte[]截取掉吗Q没有验证过Q但是照他的方式来修改也无法解决q个问题。最后还是用byte[512]的方式来解决的。先观察一D|间再?br />
]]>
]]>
]]>
outputLabel
产生<label>HTML标签,使用for属性指定组件的id,例如
<h:inputText id="user" value="#{user.name}"/>
<h:outputLabel for="user" value="#{user.name}"/>
?x)生以下标{?/SPAN>:
<input id="user" type="text" name="user" value="guest" />
<label for="user">
<h:outputLabel for="user"/>
l测?/SPAN>,值无法共?/SPAN>.
?JDOM 中,XML 元素是 Element 的实例,XML 属性就?Attribute 的实例,XML 文档本n是 Document 的实例?BR> 因ؓ(f) JDOM 对象是?Document、Element ?Attribute q些cȝ直接实例Q因此创Z个新 JDOM 对象如?Java 语言中?new 操作W一样容易。JDOM 的用是直截?jin)当的?BR> JDOM 使用标准?Java ~码模式。只要有可能Q它使用 Java new 操作W而不故弄玄虚使用复杂的工厂化模式Q对象操作即便对于初学用户也很方便?BR>
本文分两步对JDOM的应用加以介l:(x)XML创徏 ?XML解析
一、XML文档创徏
我们由零开始利用JDOM生成一个XML文档。最后的l果(h文档)看v来象q样Q?BR> <?xml version="1.0" encoding="UTF-8"?>
<MyInfo comment="introduce myself">
<name>kingwong</name>
<sex value="male"/>
<contact>
<telephone>87654321</telephone>
</contact>
</MyInfo>
1.?MyInfo 为根元素创徏文档
Element rootElement = new Element("MyInfo");//所有的XML元素都是 Element 的实例。根元素也不例外Q)(j)
Document myDocument = new Document(rootElement);//以根元素作ؓ(f)参数创徏Document对象。一个Document只有一个根Q即root元素?BR> 2.l根元素d属?BR> Attribute rootAttri = new Attribute("comment","introduce myself");//创徏名ؓ(f) commnet,gؓ(f) introduce myself 的属性?BR> rootElement.setAttribute(rootAttri);//刚创徏的属性添加到根元素?BR> q两行代码你也可以合成一行来写,象这P(x)
rootElement.setAttribute(new Attribute("comment","introduce myself"));
或?BR> rootElement.setAttribute("comment","introduce myself");
3.d元素和子元素
JDOM里子元素是作?contentQ内容)(j)d到父元素里面ȝ,所谓content是cM上面h文档?lt;name></name>之间的东东,即kingwong。罗嗦了(jin)Ҏ(gu)吧:(x)Q?BR> Element nameElement = new Element("name");//创徏 name 元素
nameElement.addContent("kingwong");//kingwong作ؓ(f)contentd到name元素
rootElement.addContent(nameElement);//name元素作ؓ(f)contentd到根元素
q三行你也可以合Z句,象这P(x)
rootElement.addContent((Content)(new Element("name").addContent("kingwong")));//因ؓ(f)addContent(Content child)Ҏ(gu)q回的是一个Parent接口Q而Elementcd时承了(jin)Contentcd实现?jin)Parent接口Q所以我们把它造型成Content?BR>
我们用同L(fng)Ҏ(gu)d带属性的子元?lt;sex value="male"/>
rootElement.addContent(new Element("sex").setAttribute("value","male"));//注意q里不需要{型,因ؓ(f)addAttribute(String name,String value)q回值就是一?Element?BR>
同样的,我们d<contract />元素到根元素下,用法上一P只是E微复杂?jin)一些:(x)
rootElement.addContent((Content)(new Element("contact").addContent((Content)(new Element("telephone").addContent("87654321")))));
如果你对q种写Ş式还不太?fn)惯Q你完全可以分步来做Q就象本节刚开始的时候一栗事实上如果层次比较多,写成分步的Ş式更清晰些,也不Ҏ(gu)出错?BR> 4.删除子元?BR> q个操作比较单:(x)
rootElement.removeChild("sex");//该方法返回一个布?yu)(dng)?BR>
到目前ؓ(f)止,我们学习(fn)?jin)一下JDOM文档生成操作。上面徏立了(jin)一个样本文档,可是我们怎么知道对不对呢Q因此需要输出来看一下。我们将JDOM生成的文档输出到控制収ͼ使用 JDOM ?XMLOutputter cR?BR> 5. ?JDOM 转化?XML 文本
XMLOutputter xmlOut = new XMLOutputter(" ",true);
try {
xmlOut.output(myDocument,System.out);
} catch (IOException e) {
e.printStackTrace();
}
XMLOutputter 有几个格式选项。这里我们已指定希望子元素从父元素羃q两个空|q且希望元素间有I?BR> new XMLOutputter(java.lang.String indent, boolean newlines)q个Ҏ(gu)在最新版本中已经不徏议用。JDOM有一个专门的用来定义格式化输出的c:(x)org.jdom.output.FormatQ如果你没有Ҏ(gu)的要求,有时候用里面的几个?rn)态方法(应该可以说是预定义格式)(j)?getPrettyFormat()可以了(jin)。我们把上面的输出格式稍微改一下,pq样Q?BR> XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
6.JDOM文档转化为其他Ş?BR> XMLOutputter q可输出?Writer ?OutputStream。ؓ(f)?jin)输出JDOM文档C个文本文Ӟ我们可以q样做:(x)
FileWriter writer = new FileWriter("/some/directory/myFile.xml");
outputter.output(myDocument, writer);
writer.close();
XMLOutputter q可输出到字W串,以便E序后面q行再处?
Strng outString = xmlOut.outputString(myDocument);
当然Q在输出的时候你不一定要输出所有的整个文档Q你可以选择元素q行输出Q?BR> xmlOut.output(rootElement.getChild("name"),System.out);
一句话QJDOM非常灉|方便Q如果你惌一步研IJDOMQ请到官方网站去看一看:(x)http://www.jdom.org
本节CZ源码Q?BR>package com.cyberobject.study;
import java.io.IOException;
import org.jdom.Attribute;
import org.jdom.Content;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
/**
* @author kingwong
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TestJDOM {
public static void main(String[] args)
{
Element rootElement = new Element("MyInfo");
Document myDocument = new Document(rootElement);
// Attribute rootAttri = new Attribute("comment","introduce myself");
// rootElement.setAttribute(rootAttri);
rootElement.setAttribute("comment","introduce myself");
//rootElement.setAttribute(new Attribute("comment","introduce myself"));
// Element sexElement = new Element("sex");
// rootElement.addContent(sexElement);
// Element nameElement = new Element("name");
// nameElement.addContent("kingwong");
// rootElement.addContent(nameElement);
rootElement.addContent((Content)(new Element("name").addContent("kingwong")));
rootElement.addContent(new Element("sex").setAttribute("value","male"));
rootElement.addContent((Content)(new Element("contract").addContent((Content)(new Element("telephone").addContent("87654321")))));
rootElement.removeChild("sex");
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
try {
xmlOut.output(myDocument,System.out);
//xmlOut.output(rootElement.getChild("name"),System.out);
//String outString = xmlOut.outputString(myDocument);
} catch (IOException e) {
e.printStackTrace();
}
}
}
二、XML文档解析
JDOM 不光可以很方便的建立XML文档Q它的另一个用处是它能够读取ƈ操作现有?XML 数据?BR> JDOM的解析器在org.jdom.input.*q个包里Q其中的DOMBuilder的功能是DOM模型的Document解析成JDOM模型的DocumentQSAXBuilder的功能是从文件或中解析出符合JDOM模型的XML?wi)。由于我们经常要从一个文仉d数据Q因此我们应该采用后者作析工兗?BR>解析一个xml文档Q基本可以看成以下几个步骤:(x)
1.实例化一个合适的解析器对?BR> 本例中我们用SAXBuilder:
SAXBuilder sb = new SAXBuilder();
2.以包含XML数据的文件ؓ(f)参数Q构Z个文档对象myDocument
Document myDocument = sb.build(/some/directory/myFile.xml);
3.获到根元?BR> Element rootElement = myDocument.getRootElement();
一旦你获取?jin)根元素Q你可以很方便地对它下面的子元素进行操作了(jin)Q下面对Element对象的一些常用方法作一下简单说明:(x)
getChild("childname") q回指定名字的子节点,如果同一U有多个同名子节点,则只q回W一个;如果没有q回null倹{?BR> getChildren("childname") q回指定名字的子节点List集合。这样你可以遍历所有的同一U同名子节点?
getAttributeValue("name") q回指定属性名字的倹{如果没有该属性则q回null,有该属性但是gؓ(f)I,则返回空字符丌Ӏ?BR> getChildText("childname") q回指定子节点的内容文本倹{?BR> getText() q回该元素的内容文本倹{?BR>
q有其他没有|列出来的方法,如果需要的话,可以随时查阅JDOM的在U文档:(x)http://www.jdom.org/docs/apidocs/index.html。当然你可以在你需要的地方d、删除元素操作,q记得上面的创徏XML的方法吗Q呵呵~~~
学习(fn)C东还是从实例学v最为快P下面单D个例子,׃上面的XMLh代码来学?fn)JDOM的XML解析。本例中d?jin)样本XML文g里一些属性和contentQ最后我们还在contact元素里插入了(jin)一个新元素<email value="wanghua@cyberobject.com" />。尽我们实C(jin)对于XML的基本操作,l心(j)的朋友可能会(x)
有疑问:(x)如果XML文档的层ơ稍微复杂一些,如果嵌套多达几十上百层的话(开个玩W)(j)Q如果靠q样从根元素一U一U地通过getChild("childname")来访问子元素的话Q将?x)非常痛苦!是的Q的是q样Q但是我们有另一个有力的工具XPathQؓ(f)什么不用呢Q这是后话!先卖个关子(手敲累啦Q下回吧Q呵呵)(j)?BR>
/*
* Created on 2004-8-21
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.cyberobject.study;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
/**
* @author kingwong
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TestJDOM2 {
public static void main(String[] args){
SAXBuilder sb = new SAXBuilder();
try
{
Document doc = sb.build("myFile.xml");
Element root = doc.getRootElement();
String str1 = root.getAttributeValue("comment");
System.out.println("Root Element's comment attribute is : " + str1);
String str2 = root.getChild("sex").getAttributeValue("value");
System.out.println("sex Element's value attribute is : " + str2);
String str3 = root.getChildText("name");
System.out.println("name Element's content is :" + str3);
String str4 = root.getChild("contact").getChildText("telephone");
System.out.println("contact Element's telephone subelement content is : " + str4 + "\n");
Element inputElement = root.getChild("contact");
inputElement.addContent(new Element("email").setAttribute("value","wanghua@cyberobject.com"));
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
String outStr = xmlOut.outputString(root);
System.out.println(outStr);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
使用XMLOutputter转换XML文g的编码例子代码片?/P>
SAXBuilder builder = new SAXBuilder();
Document doc;
Format format = Format.getPrettyFormat();
format.setEncoding("GB2312");
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(format);
File file = new File(realPath);
doc = builder.build(file);
String xmlString = outputter.outputString(doc);
apache_2.0.55-win32-x86-no_ssl.msi q个文g下蝲后安装就可以使用无需~译
jakarta-tomcat-5.5.9.exe 直接安装可以了(jin)
q入正题Q由于win默认IIS占据?0端口所以要安装Apache之前先打开 开始菜?理工具-服务选项
停止 IIS Admin Service 服务 在这个上面右键选属性把启动cd更改为禁止,以免下蝲操作pȝ重vQiis有自动开始服务造成80端口与apache冲突?/P>
接着双击apache_2.0.55-win32-x86-no_ssl.msi文gq行安装Q安装过E可选安装目录?/P>
我这里是装在?C:Apache Group目录下面Q安装程序自Z(jin)个Apache2目录Q所以安装完毕Apache文g都在C:Apache GroupApache2目录下面?/P>
安装l束后打开 http://localhost/ 应该可以看到ApacheƢ迎画面Q至此Apache安装成功?/P>
接着安装TOMCATQ关于TOMCAT的安装方法网上已l很多资源了(jin)Q而且5.0以后的TOMCAT安装很容易,直接双击q行选择安装目录一路下一步就行了(jin)?/P>
我的TOMCAT安装在了(jin)C:Tomcat5目录下。默认的TOMCAT服务端口?080Q所以安装完毕后览器里键入http://localhost:8080 应该能看到tomcat的欢q画面,是一只猫Q我惛_安熟?zhn)了(jin)?/P>
二者都正确安装后,接着开始整合工作?/STRONG>
整合二者需要apache出品的一个组Ӟ文g不大所以我们在文章内提供下?jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip 解压~后其实我们只需要modules目录里面的mod_jk2.so 文gQcopy到Apache安装目录下modules文g多wQ我们的路径是C:\Apache Group\Apache2\modules
接着在C:\Apache Group\Apache2\conf目录下徏workers2.properties文g。内容用C本编辑ؓ(f)Q?/P>
代码内容 [shm] file=${serverRoot}/logs/shm.file size=1048576 #The socket channel [channel.socket:localhost:8009] port=8009 host=127.0.0.1 #define the worker [ajp13:localhost:8009] channel=channel.socket:localhost:8009 #uri mapping [uri:/*.jsp] [uri:/*.do] [uri:/*.gv] worker=ajp13:localhost:8009 |
然后用记事本~辑C:\Apache Group\Apache2\conf\httpd.conf 文gQ在文gNq加一下内?/P>
代码内容 #服务器IP地址 NameVirtualHost 192.168.1.100:80 <VirtualHost 192.168.1.100:80> #理员EMAIL ServerAdmin gamvan@gmail.com #|站l对路径 DocumentRoot "E:\MYJAVA\myWeb" # L?如果有域名解析到q个IP可以直接写域名如 club.gamvan.com ServerName 192.168.1.100 #以下两行是日志文仉认即?/FONT> ErrorLog logs/error.log CustomLog logs/access.log common </VirtualHost> |
实际应用中最好去掉井号后面的灰色注释内容Q好?jin)APACHE搞定?jin)。接下来配置TOMCAT的虚拟目录,我想大家都很熟?zhn)Q但是我q里q是|嗦一下业队的h章标?详解 二字?BR>
扑ֈTOMCAT安装目录Q我q里是C:\Tomcat5\conf C本打开 server.xml文g ctrl+f查找到这个标{
<!-- Define the default virtual host --> <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true"> |
我们不管q个Q直接在q个标签上面加入一个完整的虚拟L配置标签Q注意要和apache配置的虚拟目录一P代码如下Q?/P>
代码内容 |
PSQapache服务器和tomcat整合后不能立卌问,需要等待一?x),可能是他俩内部握手确认合作协议呢Q?刷几下就行了(jin)。实在不行重Pq不行就重新配置一遍,如何q不行请?club.gamvan.com 今晚在线开发?/A>C来交一下,让大家一起帮助?zhn)解决?/P>
一、用links方式安装eclipse插g
假设eclipse安装目录是D:\eclipseQ待安装插g目录是D:\ eclipseplugins。以lombozQSysdeo Eclipse Tomcat Launcher plugin和xmlbuddyZ说明如何使用links方式安装eclipse插g?/P>
1、安装Lomboz
在D:\eclipseplugins中徏立如下的目录l构Q?/P>
D:\eclipseplugins\lomboz\eclipse
lomboz安装文g解压到此目录中,q个目录包含一个plugins目录Q即目录l构是这L(fng)Q?/P>
D:\eclipseplugins\lomboz\eclipse\plugins
在D:\eclipse\links目录下新建文Ӟ命名为lomboz.linkQ编辑此文gQ加入如下内容ƈ保存?/P>
path = D:/eclipseplugins/lomboz
数据的导?BR> 1 D:\daochu.dmp 中的数据导入 TEST数据库中?BR> imp system/manager@TEST file=d:\daochu.dmp
上面可能有点问题Q因为有的表已经存在Q然后它?yu)报错,对该表就不进行导入?BR> 在后面加?ignore=y 可以了(jin)?BR> 2 d:\daochu.dmp中的表table1 导入
imp system/manager@TEST file=d:\daochu.dmp tables=(table1)
基本上上面的导入导出够用?jin)。不情冉|是将表彻底删除,然后导入?BR>
注意Q?BR> 你要有够的权限Q权限不够它?x)提CZ?BR> 数据库时可以q上的。可以用tnsping TEST 来获得数据库TEST能否q上?/P>