Monday, October 21, 2013

HTML File input tag for specific file type


FILE UPLOAD

Sometimes we may need to specify the exact file type for upload/select.
This is one way to handle that.

Using File Extension(Here .csv is using. You can use any extension like .jar, .ppt etc.)
<input type="file" name="pic" id="pic" accept=".csv" />

Using File Type
<input type="file" name="pic" id="pic" accept="text/plain" />
You can use this link to find out the file types. http://www.iana.org/assignments/media-types

For selecting video files only
<input type="file" name="pic" id="pic" accept="video/*" />


For selecting audio files only
<input type="file" name="pic" id="pic" accept="audio/*" />

For   Excel Files 2010 (.xlsx) 
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />


Here is the Working Example : http://jsfiddle.net/LzLcZ/371/

Thursday, October 17, 2013

Tomcat – Java.Lang.OutOfMemoryError

Apache Tomcat server may spit this error. To solve this error you need to update catalina.sh file.

1. Locate catalina.sh in bin directory. (Eg : apache-tomcat-7.0.22/bin/catalina.sh).
2. Edit it and append this line,


JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

3. Save file and restart the server.

Thats it.




Partial example of the catalina.sh file
#   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
#                   (JSSE) installation, whose JAR files will be added to the
#                   system class path used to start Tomcat.
#
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $
# ----------------------------------------------------------------------------
 
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m 
-Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"
 
 
# OS specific support.  $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac
 
# resolve links - $0 may be a softlink
PRG="$0"


Wednesday, October 2, 2013

String array Intersect

String array Intersect 






import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
/**
 * @author devan
 * @date 03-Oct-2013
 * @email devanms@am.amrita.edu
 */

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

  String[] strings1 = { "a", "b", "c", "f" };
  String[] strings2 = { "b", "c", "d", "f" };
  Set set = new LinkedHashSet(Arrays.asList(strings1));
  set.retainAll(Arrays.asList(strings2));
  System.out.println(set.toString());
 /* 
  String[] stringIntersect = set.toArray(new String[0]); //For storing the result in another array 
  System.out.println(Arrays.toString(stringIntersect));
 */
 
 }
}


Output
======
[b, c, f]