好学IT学院:IT信息技术分享交流平台
标签:Java  来源:www.hxw.red  作者:本站整理  发布时间:2009-07-31  ★★★加入收藏〗〖手机版
摘要:关于java代码与编程的综合应用135、继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么?答:父类:package test;public class FatherClass public FatherClass() Syste……

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);
}