145、编程用JAVA解析XML的方式.
答:用SAX方式解析XML,XML文件如下:
<person></person>
<name></name>王小明
<college></college>信息学院
<telephone></telephone>6258113
<notes></notes>男,1955年生,博士,95年调入海南大学
事件回调类SAXHandler.java
import java.io.*;
import java.util.Hashtable;
import org.xml.sax.*;
public class SAXHandler extends HandlerBase {
private Hashtable table = new Hashtable();
private String currentElement = null;
private String currentValue = null;
public void setTable(Hashtable table) {
this.table = table;
}
public Hashtable getTable() {
return table;
}
public void startElement(String tag, AttributeList attrs) throws SAXException {
currentElement = tag;
}
public void characters(char[] ch, int start, int length) throws SAXException {
currentValue = new String(ch, start, length);
}
public void endElement(String name) throws SAXException {
if (currentElement.equals(name)) {
table.put(currentElement, currentValue);
}
}
}
JSP内容显示源码,SaxXml.jsp:
146、EJB的基本架构
答:一个EJB包括三个部分:
Remote Interface 接口的代码:
package Beans;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Add extends EJBObject {
//some method declare
}
Home Interface 接口的代码:
package Beans;
import java.rmi.RemoteException;
import jaax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface AddHome extends EJBHome {
//some method declare
}
EJB类的代码:
package Beans;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javx.ejb.SessionContext;
public class AddBean Implements SessionBean
{
//some method declare
}
147、如何校验数字型?
var re=/^\d{1,8}$
\.\d{1,2}$/;
var str=document.form1.all(i).value;
var r=str.match(re);
if (r==null) {
sign=-4;
break;
}else{
document.form1.all(i).value=parseFloat(str);
}