Monday 24 November 2014

package javax.servlet does not exist

add this dependency to the pom.xml file

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>

if it normal java project then add this jar to the project.

servlet-api.jar




Sunday 23 November 2014

hibernate mediumblob annotation

Use at:
"@LOB"

@Column(name = "image")
@Lob
private byte[] image;


For saving mediumblob  image to the data base

Data truncation: Data too long for column 'image'

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'image' 


TINYBLOB   :     maximum length of 255 bytes  
BLOB       :     maximum length of 65,535 bytes  
MEDIUMBLOB :     maximum length of 16,777,215 bytes  
LONGBLOB   :     maximum length of 4,294,967,295 bytes  



hibernate mediumblob annotation


Friday 21 November 2014

Tuesday 11 November 2014

GWT tab key press event

GWT tab key press event

KeyDownHandler handler = new KeyDownHandler() {
  @Override
  public void onKeyDown(KeyDownEvent event) {
    if (event.getNativeKeyCode() == 9) {
      event.preventDefault();
      event.stopPropagation();
    }
  }
}

Thursday 9 October 2014

how to get the execution directory path in java


//how to get the execution directory path in java


package com.vipul.org;

public class GetRuningPath {

/**
* @param args
*/
public static void main(String[] args) {
String classpath = System.getProperty("user.dir");
System.out.println("" + classpath);
}

}

Sunday 5 October 2014

radio button validation in jquery

<input class="attrInputs" type="radio" name="chest" value="A">
<input class="attrInputs" type="radio" name="chest" value="B">
<input class="attrInputs" type="radio" name="chest" value="C">
   
    radio button validation in jquery


==============================

if($('input[name=chest]:checked').length<=0)
{
 alert("No radio checked")
}

=======================================================
demo

black color code in css font

Black font color in csss

use



 color :#000000

Wednesday 1 October 2014

jquery get value of input text field length

jquery get value of input text field length

Demo


jquery get value of input text field length

<input type="text" id="textbox"/>

<p>Error </p>
<button type="button" id="button">Click Me!</button>

============
$('#button').click(function() {
    var value = $('#textbox').val().length;
    
    if(value >=1)
    {
    alert(value);
         $("p").hide();
    }
    else{
    
        
    }
    
 
});
 



 

jquery show hide

jquery show hide

jquery show hide Demo

<input type="text" id="textbox"/>

<p>Error </p>
<button type="button" id="button">Click Me!</button>


$('#button').click(function() {
    var value = $('#textbox').val().length;
   
    if(value >=1)
    {
    alert(value);
         $("p").hide();
    }
    else{
    $("p").show();
       
    }
   

});








get input button value jquery

get input button value jquery

<input type="text" id="textbox"/>


<button type="button" id="button">Click Me!</button>


===============================================================
$('#button').click(function() {
   
    alert($('#textbox').val());
});

==============================================================
Please find Demo here

jquery call function on button click

jquery call function on button click

<button type="button" id="button">Click Me!</button>


$(function(){
    $('#button').click(function() {
        alert("Hello");
    });
});

Demo http://jsfiddle.net/vipulg/gm68jxas/2/

jquery keydown keypress event listner

change background color on keydown and keyup.


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>

</script>
</head>
<body>

Enter your name: <input type="text">
<p>Enter your name in the input field above. It will change background color on keydown and keyup.</p>


==================
Jquery
==================
$(document).ready(function(){
  $("input").keydown(function(){
    $("input").css("background-color","yellow");
  });
  $("input").keyup(function(){
    $("input").css("background-color","pink");
  });
});
=====================================================
+++++++++++++++++++++++++++++++++++++++++++++++++++++

check input field length in jquery?

check input field length in jquery?

check input field length in jquery?
click on this
<a href="test">test</a>

<div id="selector"></div>
<input type="text" id="textbox"/>

<div id="selectorSize"></div>
<div id="name"></div>

==================================
JQuery script is
==================================
jQuery(function () {
    $('a').click(function (e) {
        e.preventDefault();
        var name = $(this).text();
        var myLength = $("#textbox").val();
        $("#selectorSize").text(myLength.length);
       
        if (myLength.length <= 6) {
              $("#name").text("ERR");
             $("#name").addClass("error");
         }
       
        $("#selector").text(name);
        $("#textbox").val(name);
    });
});
============================================

View Demo Here

Saturday 13 September 2014

How to Make Spring form input as Read Only

Spring JSTL form:input tag the proper syntax is readonly=”true"
==============================================
<form:input path="caseId" readonly="true"/>

=======================================================================
And if you are using HTML tag input then this will be the tag readonly="readonly"

<input name="caseId"  readonly="readonly" class="required"/>
=======================================================================

spring mvc form input readonly syntax is readonly="true"

for Html tag it is  readonly="readonly"

how to set up html image height width

how to set up html image height width
======================================================

<html>
<body>

<img src="vipulImagePath.gif"  width="42" height="60">

</body>
</html>

======================================================
We have image tag attributes height width
======================================================

Saturday 6 September 2014

All Pages link

===================================================================
Glassfish server runtime requires full JDK instead of JRE
===================================================================
Starting Tomcat v7.0 server at localhost has encountered a problem in eclipse
===================================================================
Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
===================================================================
Fixed error Project facet Java version 1.7 is not supported in eclipse
===================================================================
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed
===================================================================

Friday 4 July 2014

How do I compare strings in Java

Use equals () to compare

two string 



package com.vipul;

public class StringComporation {

      /**
      * How do I compare strings in Java
      * @param args
      */
      public static void main(String[] args) {
            String fooString1 = new String("foo");
            String fooString2 = new String("foo");
            // Evaluates to true
            if(fooString1.equals(fooString2));
            {
                  System.out.println(fooString1);
            }
           

      }

}
==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

How to convert StringBuilder to String

package com.vipul;

public class StringBuildertoString {

      /**
      * How to convert StringBuilder to String
      * @param args
      */
      public static void main(String[] args) {
            StringBuilder sb = new StringBuilder();
                sb.append("test");

                System.out.println(sb.toString());

      }

}

==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

How to concatenate or combine two Strings

How to combine two Strings


package com.vipul;

public class Stingconcatenate {

      /**
      * How to combine two Strings
      * @param args
      */
      public static void main(String[] args) {
            String firstName = "Vipul";
            String lastName  = "Gulhane";
            String fullName  = firstName + lastName;
            System.out.println("Stingconcatenate is "+fullName);
      }

}

==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

How to remove the last character in StringBuilder

How to remove the last character in StringBuilder


package com.vipul;

public class StringBufferDelete {

      /**
      * How to remove the last character in StringBuilder
      * @param args
      */
      public static void main(String[] args) {
            String text2 = "Test";         
              StringBuffer text=new StringBuffer(text2);
           // ...
           final int length = text.length();
           if ( length > 0 ) {
                // We have remove the last character.
                text.deleteCharAt( length - 1 );
           }
           System.out.println(text);
      }

}

==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

Getting the Current Working Directory in Java

package com.vipul;

public class CurrruntPath {

      /**
      * Getting the Current Working Directory in Java
      * @param args
      */
      public static void main(String[] args) {
            System.out.println("Working Directory = " +
                    System.getProperty("user.dir"));
       

      }

}

convert string to ascii value

this is example of StringToAscii convertion in java.

string get character java ascii to value

package com.vipul;

public class StringToAscii {
      public static void main(String[] args) {

            char character = 'a';
            int ascii = (int) character;
            System.out.println("ascii is"+ascii);
      }
}


Output is ::
================================
ascii is:97
================================

one to many relationship example in hibernate annotations


This was one to many relationship example in hibernate annotations.how to achive one to many mapping in hibernate java integration with mysql.

this was the the database design.

===========================================================
1)pom.xml
===========================================================


Sunday 18 May 2014

invalid target release 1.7 - Maven

invalid target release 1.7 - Maven

If we are getting this kind of error then please check maven complier  is mismatch or not and correct it


Saturday 10 May 2014

fixed Unsupported major.minor version 51.0

Recently I moved to Java 7.  I was doing coding , I opened my old project which was in  Java 1.6.
my eclipse started giving me this error which is :
=========================
Unsupported major.minor version 51.0
=========================================
java.lang.UnsupportedClassVersionError: com/javapapers/spring/SpringEmail : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main" 
=========================================
I found solution for this 

it was version mismatch with jre

J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

I recompile with java 1.6


Saturday 12 April 2014

Fixed How to split a String by space or whitespace

Fixed How to split a String by space or white space

/*
 *
 */
public class SplitByWhitespace {

    /**
     * @param args
        public static void main(String[] args) {
       
        String  str = "How to split a String by space";
        String[] splited = str.split("\\s+");
        for(String splitedValue : splited){
        System.out.println("splitedValue :"+splitedValue);
        }
    }
}
/* Result
 *
 * splitedValue :How
splitedValue :to
splitedValue :split
splitedValue :a
splitedValue :String
splitedValue :by
splitedValue :space
 */

fixed how to remove space in string in java

fixed how to remove space in string in java.
resently i have to remve from string here is exmape how to remove Whitespace from given string

/*******************************************************************************/
public class RemovingWhitespace {

    /**
     * @param args
     */
    public static void main(String[] args) {
       
        String st="2013 2014 2015 2016 3017 2018 2019 2120";
       
        String newString =st.replaceAll("\\s+","");
       
        System.out.println(newString);
    }

}

/*******************************************************************************/
/* Result is
 * 20132014201520163017201820192120
 */