Posts

Image resizing in Java

Image resizing to a ration of standard size (For Ex: 1024x800   to 800x600) public void  resizeFile(File original,  int width, int height){                 int newWidth=0;                 int newHeight=0;                 BufferedImage bufferedImage = ImageIO.read(original);                       int orginalWidth=bufferedImage.getWidth();                 int orginalHeight=bufferedImage.getHeight();                 float ratioWidth= (float)orginalWidth/(float)width;                 float ratioHeight=(float)orginalHeigh...

trim() function Java Script

Use these function in Java Script body : ---------------------------------------------------------------------------------------------------- function trim(stringToTrim) {     return stringToTrim.replace(/^\s+|\s+$/g,""); } function TestTrimString(){      var testString="  Hello!  "     document.write("String before  triming:" + testString );       document.write("String after     triming:" + trim(testString) ); } ------------------------------------------------------------------------------------------------------

How to get session attribute in struts 2 tag

                            How to get session attribute in struts 2  <s:if test> tag <s:if test='%{#session.USERID != null}' >         // do something </s:if> <s:else if test='%{#session.USERID =="admin"}' >    // if user is admin in USERID attribute of session, do something   </s:else if> <s:else>    //do other things </s:else>

Validate URL using Java Script

Validate URL using Java Script /*   Java Script code----------------------------- -------------------------------------------------------------------------------------------------- function isUrl(urlByUser) {           var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;        return regexp.test(urlByUser);   } // Here "FieldName" is the id of HTML element in your html form if((isUrl(document.getElementById("FieldName").value))){       alert(''Valid URL");                                                               ...

How to get Height and Width of an image using java script :client side validation

       Validate Image height and width before uploading ---------------------------------------------------------------------------------- /*    <script language="javascript">         function getWidth()         {             var testImage = document.getElementById('testImage');             alert(testImage.clientWidth);         }         function getHeight()         {             var testImage = document.getElementById('testImage');             alert(testImage.clientHeight);         }   ...

How to Converts YYYY-MM-DD to dd.MM.yyyy format in java as date in String

  Converts YYYY-MM-DD to dd.MM.yyyy format in java as (date in String) ========================================================= public static String getDateFormatDDMMYYY(String dateStr) {         String[] dateParts = dateStr.split("-");         StringBuffer sb = new StringBuffer();         for (int ii=dateParts.length-1; ii>0; ii--) {           sb.append( dateParts[ii] + "." );         }         sb.append( dateParts[0] );         return sb.toString();     } ===========================================================

Convert String to date in java

 Convert String(yyyy-MM-dd HH:mm:ss ) to date in java --------------------------------------------------------------------------- public static Date getCurrentTimeStamp(){         String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";         DateFormat formatter= new SimpleDateFormat(DATE_FORMAT);         Calendar c1 = Calendar.getInstance(); // today                System.out.println("Today is " + formatter.format(c1.getTime()));                 try {                         Date date = (Date)formatter.parse(formatter.format(c1.getTime()));              System.out.println("Date after converted from string: " + date);       ...