Friday, February 1, 2013

Run existing tomcat installtion from eclipse and command line

1. When starting tomcat from eclipse, usually a separate tomcat instance configured by eclipse will start. If you want to run the existing tomcat instance with all web apps in it, you will need to double click on the tomcat item in server tab, and then select Server location to "Use Tomcat installation". Notice that the server path below will point to the existing tomcat you already installed before.
Start the tomcat from eclipse, you will see all you existing web app are there.

2. When run tomcat from mac from command line, you will need to update the file permission to make it work as below:

chmod 755 /Users/i826633/Documents/SMP/apache-tomcat-7.0.57/bin/*

./startup.sh
./shutdown.sh

3. the role name for tomcat user are case sensitive, so "administrator" is different from "Administrator"

Monday, November 26, 2012

Automatically map XmlhttpRequest post data to MVC action partameters

After converting a html Form to a xmlHttpRequest post request, the MVC action method can no longer get the mapped parameter value sent from client. The post data string is the exact between the two cases.

It turns out it is caused by not setting the Content-Type header in xmlhttprequest  object, and it is reasonable that server action method will not try to map the parameter value from post data, as with post request, the post data may be binary, json or any other formats.

So in order to fix the issue, the only required change is setting the content type explicitly for the request:

req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

And the server action method just stars to work again.

Monday, November 5, 2012

Install iso file on Windows 7 with WinRAR

The Virtual CD application provided by Microsoft no longer supports Windows 7, so it cannot by used to install iso file. If you do not want to burn the iso file into a real DVD, or using third party application to mount  the iso file to a virtual driver, you can just unzipped the iso file using WinRAR, which is a well known safe application to install on Windows 7.
After it is unzipped, just start the setup file (setup.exe), it should work as if it is installed from a DVD. Certainly, this will not work if you need to boot the box from the iso file.

Sunday, November 4, 2012

MS SQL Server 2008 sa authentication failure

Just installed a sql server 2008 and try to login using sa account. The login failed and few issues have to be checked using Windows authentication account before making sa account work:

1. Login SQL server management studio with windows account, right click server property menu, select Security, and check "SQL Server and Windows Authentication mode" under Server authentication section.

2 Still in server management studio, select Security folder, select sa user and right click property, check status item, and be sure it is Granted and Enabled in settings page


Monday, October 15, 2012

When do you need to send AutoRelease message to an object

If the object is created with convenience method, like [NSMutableArray arrayWithCapacity], then the convenience constructor already sends the AutoRelease message to the object when it is created, so when the auto release pool or block is ended, it will send the release message to the object.

If the object is created with the alloc or copy constructor, and the object is returned to caller as a method return value or output parameter, then you should call AutoRelease message on the object. The reason is the receiver does not create the object, so he is not the own of the object and is not responsible to release the object. While after the object is returned by the method, then the creator of the object lose the control of the object and cannot actively release the object. The only limited control the original creator has on the object is sending autorelease message to it before relinquishing the control of the object, and that will be sure the object gets released sometime when the autorelease pool is closed.

However, in both cases, if the autoreleased object is created on a long-living auto release pool, then the object will last for long time and that will cause the object dose not be released quickly.

Sunday, October 14, 2012

javascript function scope sample

Javascript scope is used to enclose the internal logic and only expose the necessary public information to external. Basically, within a object or function scope, only properties or function  defined on the object are visible to external as public info through the object. Any local variables defined with var, or inner function are only available to internal logic.

var globalFunction = function () {    // global, can be accessed anywhere.
    alert('hello world');
}

var containerFunction = function () { // globale namespce, can be accessed anywhere.
   
    var subFunction = function () {    // private namespace method
        alert("I'm Private");
        globalFunction();              // We can access global Function here 2 levels deep.
    }
   
    containerFunction.test = function () {  //public namespace method
        alert("test");
    }

    callableFunc = function () {   //global method, because variable is global
        alert("callable");
    }

    function localFunc(){   //only visible to local
       alert("local");
    }

    varible ="8";  //unlike function, new varibles without var gets added to global window object

    globalFunction();                 // We can access global Function here 1 level deep.
    subFunction();                     // We can access subFunction inside containerFunction.
    localFunc();
    alert(varible);
}

containerFunction();
containerFunction.test();
callableFunc();
alert(varible);

//failure cases
//test();  //test is not visible in global scope
//subFunction(); //namespace private method and only exists inside containerFunction
//containerFunction.callableFunc(); //callableFunc is not belonging to namespace, it is global
//localFunc() //not visible

Note, unlike 

javascript self invoking function parameter

The sample javascript self invoking function is defined as follows
(function(parmeter1){
    alert(parameter1);
}("hello world");

Notice the data in the last parentices is the actual caller that will invoke the function, which passes the argument's value as "hello world".
Inside the function definition, the parameter1 is replaced by the string "hello world", and shows the alert.