The JQuery Code:
$(document).ready(function() {
CUSTOM JQUERY PLUGIN
$.fn.image = function(src, f){
return this.each(function(){
var i = new Image();
i.src = src;
i.onload = f;
this.appendChild(i);
});
}
-- on button click output image generating servlet to the div.
$('#clickme_button').click(function(){
$("#the_div").image('/rcms/chequeImageServlet',function(){
});
});
The Servlet:
response.setContentType("image/jpg");
//RESOLVE CACHING ISSUES
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
try {
byte[] rb = null;
Cheque cheque = chequeEjb.getCheque(new Long(13));
if (cheque != null) {
rb = (byte[]) cheque.getImgFront();
cheque entity a POJO which stores images as Serializable , in DB Blob
if (rb != null && rb.length > 0) {
response.reset();
response.getOutputStream().write(rb, 0, rb.length);
response.getOutputStream().flush();
}
}
} finally {
response.getOutputStream().close();
}
}
Hats off to the below blog link:
http://letmehaveblog.blogspot.com/2006/08/simple-jquery-plugin-to-load-images.html
Tuesday, May 18, 2010
Saturday, May 15, 2010
JPA Cache Refresh
If you are a beginer to JSF and JPA,sometimes, you may wonder why your web page does not reflect the database table values accurately, especially when the table values were modified externally.(Manually).
This happens, because when you (by default) fetch data using JPA entity manager, the values are fetched from the Entity Cache. So basically when you update the database table externally, the Entity Cache needs to be updated as well.
To get over this issue, simply,
fetch the data like this:
e = (Employee)em.createQuery("SELECT e FROM Employee e WHERE e.id = :id")
.setHint("toplink.pessimistic-lock", "Lock")
.setParameter("id", primaryKey)
.getSingleResult();
http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t.html
This happens, because when you (by default) fetch data using JPA entity manager, the values are fetched from the Entity Cache. So basically when you update the database table externally, the Entity Cache needs to be updated as well.
To get over this issue, simply,
fetch the data like this:
e = (Employee)em.createQuery("SELECT e FROM Employee e WHERE e.id = :id")
.setHint("toplink.pessimistic-lock", "Lock")
.setParameter("id", primaryKey)
.getSingleResult();
http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t.html
Monday, April 19, 2010
How to inject and look up custom resources in Glassfish
http://blogs.sun.com/chengfang/entry/how_to_inject_and_look
Monday, March 29, 2010
Set up a cluster (Glassfish v2.1.1) and load balancer (sjws7)
If you come accross this post by any chance, I just wanted you to know that
if you follow the below link's instructions to the dot, you will not face difficulties as its pretty straight forward.
https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html
if you follow the below link's instructions to the dot, you will not face difficulties as its pretty straight forward.
https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html
Monday, January 11, 2010
Adding an auto startup service in RH Linux 5
1.) Create a executable file.
vi filename.
2.) Add the below content to the file
#!/bin/sh
#chkconfig: 2345 80 05
#description: my service
echo "starting up"
3.)Place the scrip in etc/init.d/rc.d
4.)Make it executable: chmod a+x filename
5.)add the filename to the executing sequence using: chkconfig --add filename
Notes:
Bios -- > Master Boot Record -- > Kernel -- >Init.
read linux about startup
to see the PID of init:
ps -ef | grep init
In short, the init performs tasks that are outlined in /etc/inittab.
The folders in etc/init.d/rc.d
/etc/rc.d. there are a set of files rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6,
the system uses these files (and/or directories) to control the services to be started.
Note: to see all the auto initializing scripts
type : chkconfig --list
startup sequence in init with chkconfig
vi filename.
2.) Add the below content to the file
#!/bin/sh
#chkconfig: 2345 80 05
#description: my service
echo "starting up"
3.)Place the scrip in etc/init.d/rc.d
4.)Make it executable: chmod a+x filename
5.)add the filename to the executing sequence using: chkconfig --add filename
Notes:
Bios -- > Master Boot Record -- > Kernel -- >Init.
read linux about startup
to see the PID of init:
ps -ef | grep init
In short, the init performs tasks that are outlined in /etc/inittab.
The folders in etc/init.d/rc.d
/etc/rc.d. there are a set of files rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6,
the system uses these files (and/or directories) to control the services to be started.
Note: to see all the auto initializing scripts
type : chkconfig --list
startup sequence in init with chkconfig
Sunday, December 27, 2009
Windows Hard Drive Serial Number
public static String getSerialNumber(String drive) {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}
Execute an OS Command
public static void main (String [] args) throws IOException {
String [] Command = null;
if (System.getProperty("os.name").equals("Linux")) {
Command = new String[1];
Command[0] = "df";
}
if (System.getProperty("os.name").equals("Solaris")) {
Command = new String[2];
Command[0] = "df";
Command[1] = "-k";
}
if (Command == null) {
System.out.println("Can't find free space on this OS");
System.exit(1);
}
Process Findspace = Runtime.getRuntime().exec(Command);
BufferedReader Resultset = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));
String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
}
}
}
String [] Command = null;
if (System.getProperty("os.name").equals("Linux")) {
Command = new String[1];
Command[0] = "df";
}
if (System.getProperty("os.name").equals("Solaris")) {
Command = new String[2];
Command[0] = "df";
Command[1] = "-k";
}
if (Command == null) {
System.out.println("Can't find free space on this OS");
System.exit(1);
}
Process Findspace = Runtime.getRuntime().exec(Command);
BufferedReader Resultset = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));
String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
}
}
}
Subscribe to:
Posts (Atom)