星期五, 十一月 18, 2005

Javascript:getElementByID getElementByName

得到当前form元素的表现层对象。

可以通过.getElementByID
或.document.forms['name'].elements['tagname']

来得到

星期六, 十一月 05, 2005

Tips:不能预先确定的动态数组.

Q:需要一个长度不固定,完全需要动态变化的array对象。

A:使用:java.io.ByteArrayOutputStream
最后使用ByteArrayOutputStream.toByteArray,得到最终的数组

典型代码:

protected Class getClassFromJar(InputStream is, String className) throws Exception
{
System.out.println("getClassFromJar try find "+className);
JarInputStream jis = new JarInputStream(is);
String rname = className;
rname = rname.replace ('.', '/') + ".class";//重要,必须还原为目录格式
JarEntry entry=null;
Class tmp=null;
while ((entry = jis.getNextJarEntry()) != null)
{
System.out.println(entry.getName());
if(entry.isDirectory()) continue;
if(entry.getName().equals(rname))
{
System.out.println("find it!!!!");
// int size=(int)entry.getSize();
// if(size==-1)throw new Exception("size is -1");
// System.out.println("size:"+size);
int status;
byte[] b= new byte[4096];
ByteArrayOutputStream buf = new ByteArrayOutputStream();
while((status = jis.read(b))!=-1)
{
System.out.println("read ..."+status);
buf.write(b,0,status);
}
System.out.println("All Read is "+buf.size());
byte[] classByte= buf.toByteArray();
buf.close();
tmp = defineClass(className,classByte,0,classByte.length);
jis.close();
return tmp;
}
}
return tmp;
}