Posts

Showing posts from July, 2011

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");                                                                  return true;                                } else{  alert(''Sorry, invalid walk URL.  Please enter URL starts with http:// or www.");    return false; } -------------------------------------------------------------------------------------------------- */

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);         }         </script> */ // HTML code <!--- <BODY>         <input type="file" id="testImage" value="browse"/>         <input type="button" value="get Width" onclick="getWidth()"/>         <input type="button" value="get Height" onclick="getHeight()"/>     </BODY> ---> ------------------------------------------------

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);              return date;         } catch (ParseException e) {             // TODO Auto-generated catch block             e.printStackTrace();             return null;         }              }

Updating more than 1 column of a table in MYSQL

Updating more than 1 column of a table in MYSQL =============================================== UPDATE tablename SET col1=?,col2=?  WHERE col3 = ?" ? = your own value, what you want to update on what condition. ===============================================

Date Format(yyyy-MM-dd HH:mm:ss) in java

 Date Format(yyyy-MM-dd HH:mm:ss) in java  ============================================================ public static String getCurrentTimeStamp(){         String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";         SimpleDateFormat sdf =               new SimpleDateFormat(DATE_FORMAT);         Calendar c1 = Calendar.getInstance(); // current date and time by system         System.out.println("Today is " + sdf.format(c1.getTime()));         return sdf.format(c1.getTime());       } ============================================================