Monday, April 21, 2008
Spring framework resources
Tuesday, April 15, 2008
Useful Javascript functions
function isEmpty(fieldName){
/*
* This method will return true if the field is empty and return
* false if it is not empty.
*/
emptyFlag = true;
if (fieldName.value == ''){ //to check the given value is empty or not
return true;
}
else{
for(i=0;i<(fieldName.value).length;i++)
{
if((fieldName.value).charAt(i)!=''){
emptyFlag = false;
break;
}
}
return emptyFlag;
}
}
#Today's date
var date = new Date();
var d = date.getDate();
var m = date.getMonth() + 1;
var yy = date.getYear();
var day = (d < 10) ? '0' + d : d;
var month = (m < 10) ? '0' + m : m;
var year = (yy < 1000) ? yy + 1900 : yy;
//put the day, month and year in whatever format you require.
var todayDt = year+"-"+month+"-"+day
document.write(todayDt);
Friday, April 11, 2008
Retrieving website content with Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class WebContent
{
URL url = null;
URLConnection urlConn = null;
BufferedReader br = null;
public WebContent(String urlStr)
{
try
{
if (urlStr != null)
{
url = new URL(urlStr);
urlConn = url.openConnection();
br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String line = null;
StringBuffer sbf = new StringBuffer();
File outFile = new File("out.txt");
FileWriter fw = new FileWriter(outFile);
while ((line = br.readLine()) != null)
{
fw.write(line);
fw.write("\n");
}
}
}
catch (MalformedURLException mue)
{
System.out.println("mue = " + mue.getMessage());
}
catch (IOException ioe)
{
System.out.println("ioe = " + ioe.getMessage());
}
finally
{
if (br != null)
{
try
{
br.close();
}
catch (IOException ioe)
{
}
}
}
}
public static void main(String args[])
{
try
{
WebContent webObj = new WebContent("http://www.yahoo.com");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}