Monday, June 15, 2009

IE6 Ajax Problem with included .js file

Hi All,

Recently i got to make a site that was to be used globally in different browsers, i made this site using jsp and other bunch of technologies and frameworks. The site also has to be compactible to all known browsers world wide including blackberry and safari for iphone. On during the development stage i found a very strange problem in internet explorer 6, i included a javascript file for ajax and created some of its instances in calling page javascript code, the browser behaved very strangely,

It sometimes was able to create an instance of that ajax object and sometimes was not able to create an instance. Well, in ie7 the code worked like a butter. I finally concluded of not using that included javascript code and directly using that function code in the calling jsp page.

Check out the below scenerio:

*********My ajax.js file
/*
This function returns XmlHttpRequest Object for ajax support
*/
function getXmlHttpObject(){

//identify the browser
if (window.XMLHttpRequest) {
//alert(" you are using IE7 or mozilla");
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
if (xmlHttp.AJAX){
alert('firefox ajax support found');
}

}catch (e){
// Internet Explorer
var versions = ['Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
for (var i = 0; i < versions.length ; i++){
try {
xmlHttp.AJAX = new ActiveXObject(versions[i]);
if (xmlHttp.AJAX){
alert('internet explorer ajax support found');
break;
}
}catch (objException) {}
}
}
return xmlHttp;

} else {
//alert(" you are using IE6");

try {
//alert("hello am in");
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
//alert("hello am out");

if (xmlHttp == null){
alert('internet explorer ajax support not found');
}
}catch (objException) {}
return xmlHttp;
}
}



****************My.jsp (The calling page)



function checkAjaxInIe()
{
var xmlHttp = getXmlHttpObject();
if (xmlHttp == null)
{
alert("Your browser does not support AJAX!");
return;
}

}


After implementing this scenerio, try running this code on ie6 with script debugger activated, if you run this code 100 times, you will get probability of the calling page creating instance of included js file only 50 times from 100 times.

To resolve this, i simply included the included file's ajax function in all my jsps.

Cheers!!!

Ujjwal B Soni

Monday, May 4, 2009

Difference of JAVA 1.6 and JAVA 1.5

Here's d mathematical Difference of JAVA 1.6 and JAVA 1.5

==>JAVA 1.6 - JAVA 1.5
==>JAVA(1.6-1.5)
==>JAVA(0.1)
==> JAVA(0)
==> 0

Sunday, May 3, 2009

JDesktop Integration Components

If you have been a Java developer for a while you may have had the experience of being told that Java can't do everything that native C can. You may have struggled with the HMTLEditor pane while Windows developers down the hall embed Internet Explorer into their programs with just a few lines of code. I'll admit it: as great as Java is, there are times I long for the features and system access of native programming. Well, we don't have to wait any longer.

JDesktop Integration Components, or JDIC, is a catchall project for a set of modules that gives Java developers access to native features through cross-platform APIs. It was started by the Desktop group at Sun to let Java applications better integrate with the desktop on which they are running. They made JDIC open source to as a way to get rapid feedback from developers on desired features, as well as bug reports. While there are no current plans to do so, the JDIC team is looking into pulling some of the JDIC features into a future version of the core Java libraries.

JDIC is broken up into five components and one incubator project:

Desktop: Launches desktop programs to open, edit, print, and mail files.
Filetypes: Sets desktop file type associations.
Browser: Embeds a native web browser (Internet Explorer or Mozilla) into an AWT canvas.
Packager: Command-line tools for converting Java Web Start programs into native installers.
Tray API: Support for system tray icons and pop-up menus.
SaverBeans: System screensavers in Java

The API is available at :

https://jdic.dev.java.net/

Friday, May 1, 2009

Java file copying

using java.nio for super-speedy copies. More readable and less prone to errors than using Input/Output stream pairs and a byte buffer

try {
// Create channel on the source
FileChannel srcChannel = new FileInputStream("srcFilename").getChannel();
// Create channel on the destination
FileChannel dstChannel = newFileOutputStream("dstFilename").getChannel();
// Copy file contents from source to destination
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
// Close the channels
srcChannel.close();
dstChannel.close();
} catch (IOException e) {
}

Hibernate Statistics

This is pretty cool. When you're experimenting with different mapping strategies, you can get Hibernate to provide you with stats for the number of queries, fetches, cache hits, and all manner of other operations.
So, just write a unit test that excercises the code you want to optimise, set stats on beforehand and dump them out afterwards. Then try a few different strategies and see which one gives you the right combination of numbers. It's not a substitute for a proper performance test harness and a profiler, but it looks like an invaluable tool for diagnosing problems.

Hibernate 3 also ships with a complete statistics and metrics API that allows you to figure out *everything* that is happening under the covers. All you have to do is a.) enable staticstics for the session factory and b.) retrieve the statistics and use them. Getting them an enabling them is easy:
SessionFactory sessionFactory = getSessionFactoryForApplication();
Statistics stats = sessionFactory.getStatistics();
stats.setStatisticsEnabled(true);

The tricky part (or at least the part that requires the most attention) is figuring out what statistics are available, and what they really mean. There are a billion methods available on the top level, but here is a glimpse (note, all of these values are based off of when statistics were enabled):
For more info read post on below link : http://www.javalobby.org/java/forums/t19807.html

Cheers!!!

Ujjwal B Soni

Myeclipse IDE 7.1 update

Hi Friends,

I switchbacked to Myeclipse 7.1 from Myeclipse 6.5 since the day 7.1 got released. But, yesterday when i updated the copy of 7.1, the update went all successful but, unfortunately all got stucked up after a restart, the ide went all mad. It restricted all my javascript and jsp codes. So, i removed it from my system, downloaded a fresh copy from web (without updates). Again, it restricted my jsp and javascipt files. I spent almost half of my day in installing 6.5 again and switching back all my projects. well, the conclusion is old is gold......

So friends, never ever try to update 7.1, it will take you to the hell.

Cheers!!!

Ujjwal B Soni

Wednesday, April 29, 2009

Running java applications as services

Java Service Wrapper allows a Java application to be run as a Windows service or a Unix daemon. It works under FreeBSD, GNU-Linux, MacOS X, Solaris, AIX, Windows NT/2000/XP/2003, Irix, HP-UX and DEC OSF1.