Friday, April 24, 2009

Basic Sevlet Program

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;
public class SomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Use "request" to read incoming HTTP headers (e.g. cookies) // and HTML form data (e.g. data the user entered and submitted) // Use "response" to specify the HTTP response line and headers // (e.g. specifying the content type, setting cookies). PrintWriter out = response.getWriter(); // Use "out" to send content to browser }}

Friday, March 20, 2009

Convert from String to date

public static java.sql.Date getSqlDate(String strDate) {
java.sql.Date sqlDate=null;
if(strDate!=null && !strDate.equals("")){
SimpleDateFormat formatter=null;
try{
formatter=new SimpleDateFormat("dd/MM/yyyy");
sqlDate = new java.sql.Date( (formatter.parse(strDate)).getTime() );
}catch(ParseException e){
// log.debug("Exception while converting to sql date: " + strDate);
e.printStackTrace();
}finally{
formatter=null;
}
}
return sqlDate;
}

Wednesday, March 18, 2009

Get Date before given date

public static boolean dateBefore(String toDate,String fromDate){
DateFormat df = new SimpleDateFormat("dd/MM/yyyy") ;
Date ssFromDate = null ;
Date ssToDate = null ;
if(fromDate!=null && toDate!=null ){
try{
ssFromDate = df.parse(fromDate) ;
ssToDate = df.parse(toDate) ;
if((ssToDate.before(ssFromDate)))
{
return true;
}
else
{
return false;
}
}catch(Exception e){
e.printStackTrace();
}finally{
df=null;
ssFromDate= null;
ssToDate=null;
}
return true;
}
return false;
}

Monday, February 9, 2009

To get Date in String

public static String getStrDate(XMLGregorianCalendar xCal) {
String strDate=null;
if(xCal!=null){
StringBuffer sb=null;
try{
sb=new StringBuffer();
sb.append(xCal.getDay());
sb.append(CommonData.DATE_SEPERATOR);
sb.append(xCal.getMonth());
sb.append(CommonData.DATE_SEPERATOR);
sb.append(xCal.getYear());
strDate=sb.toString();
}catch(Exception e){
e.printStackTrace();
}finally{
sb=null;
}
}
return strDate;
}

Sunday, February 8, 2009

Is Number Function

public static boolean isNumber(String str)
{
boolean number=false;
try{Integer.parseInt(str);
number=true;
}catch(NumberFormatException n)
{
number=false;
}
return number;
}