Saturday, May 23, 2009
AJAX SIMPLE EXAMPLE
function XYZ() /////call this function
{
url = "Dog" //Servlet Name
if(window.XMLHttpRequest)//non IE
{
req = new XMLHttpRequest();
try
{
req.open("GET",url,true);
req.onreadystatechange=all_list_show;
}
catch(e)
{
alert("cannot connect to server");
}
req.send(null);
}
else if(window.ActiveXObject)//IE
{
try
{ req=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{ req=new ActiveXObject("Microsoft.XMLHTTP");
}
if(req)
{ req.open("GET",url,true);
req.onreadystatechange=all_list_show;
req.send(null);
}
}
}
function XYZOUT()
{ if(req.readyState==4)
{ if(req.status==200)
{
document.getElementById('div_id').innerHTML=req.responseText;
}
}
}
Saturday, May 2, 2009
Adding Files in Jar Files
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
public class CreateJarFile {
public static int BUFFER_SIZE = 10240;
protected void createJarArchive(File archiveFile, File[] tobeJared) {
try {
byte buffer[] = new byte[BUFFER_SIZE];
// Open archive file
FileOutputStream stream = new FileOutputStream(archiveFile);
JarOutputStream out = new JarOutputStream(stream, new Manifest());
if (tobeJared[i] == null || !tobeJared[i].exists()
|| tobeJared[i].isDirectory())
continue; // Just in case...
System.out.println("Adding " + tobeJared[i].getName());
// Add archive entry
JarEntry jarAdd = new JarEntry(tobeJared[i].getName());
jarAdd.setTime(tobeJared[i].lastModified());
out.putNextEntry(jarAdd);
// Write file to archive
FileInputStream in = new FileInputStream(tobeJared[i]);
while (true) {
int nRead = in.read(buffer, 0, buffer.length);
if (nRead <= 0)
break;
out.write(buffer, 0, nRead);
}
in.close();
}
out.close();
stream.close();
System.out.println("Adding completed OK");
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error: " + ex.getMessage());
}
}
public static void main(String args[]) {
File f=new File("c:\\abc");
File af=new File("c:\\xyz.jar");
new createJarFile().createJarArchive(af,f.listFiles());
}
}
Subscribe to:
Posts (Atom)