Noticed that Tomcat sometimes uses different time zone other than that of the system.
Solution is to define a TZ environment variable in the user profile and use the user to start up Tomcat.
e.g. TZ=US/Eastern
Monday, February 23, 2009
Saturday, February 21, 2009
CVS User
I used webmin to initialize the CVS repository and it was owned by root:root.
The default repository path is /var/cvs.
To enable a normal "cvsuser" write into the repository, I chown -R cvsuser.cvsgroup /var/cvs.
The default repository path is /var/cvs.
To enable a normal "cvsuser" write into the repository, I chown -R cvsuser.cvsgroup /var/cvs.
Java 6 on CentOS 5.2
Can't shutdown Tomcat because of the memory restriction when initialize VM.
After yum install jpackage-utils, it solved.
After yum install jpackage-utils, it solved.
PostgreSQL Authentication
PostgreSQL default authentication control really sucks. I modified it like this,
- su - postgres
- psql
- show hba_file;
- vi the hba_file and comment out all default settings
- add a line "local all all md5"
- now it works from command line and phpPgAdmin web screen
Install Java 6 on CentOS 5.2
- run /usr/sbin/alternatives --config java, it gives no response.
- run uname -m and it gives i386. it means it is a linux not a linux64.
- download jdk rpm from java.sun.com, at the time, sun provides JDK 6 Update 12. select the Linux and the rpm.bin
- chmod of the bin file and make it executable, run it
- Get error -bash: ./jdk-6u12-linux-i586-rpm.bin: /bin/sh: bad interpreter: Permission denied
- after some research, i realized that the /tmp is shared managed. it won't allow me to run any scripts there. so i moved the bin file to my home directory and run it, it installed the java automatically
- run rpm -qa | grep java and got jdk-1.6.0_12-fcs, run rpm -qa | grep sun also returns a bunch of packages
- run /usr/sbin/alternatives --config java, it still gives no response but run java -version, it gives the 1.6.0_12 back.
- done.
Monday, February 09, 2009
Unicode in Web Application
Let's say you store a unicode string in a database. The database encoding is UTF-8. The string is 似水流年.
In your web application, you allow users type 似水流年 and you get it from HTTP request and obtain a string.
When you compare the string obtained from request and the string stored in the database, they will not match.
What you need to do is to convert the non-unicode string to unicode. Here is one of the way, simple and elegant.
str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
You would need to handle the UnsupportedEncodingException, but I doubt if there is any JVM not supporting ISO-8859-1 to UTF-8 conversion.
I am not sure if the ISO-8859-1 shall be different on different servers. I tried on my development workstation which is a Windows XP + Eclipse 3.3 + Tomcat 6 + Java 1.6 and my production server which is a Linux RH + Tomcat 6 + Java 1.6. They all work very well and so far I am OK with it hard coded.
In your web application, you allow users type 似水流年 and you get it from HTTP request and obtain a string.
When you compare the string obtained from request and the string stored in the database, they will not match.
What you need to do is to convert the non-unicode string to unicode. Here is one of the way, simple and elegant.
str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
You would need to handle the UnsupportedEncodingException, but I doubt if there is any JVM not supporting ISO-8859-1 to UTF-8 conversion.
I am not sure if the ISO-8859-1 shall be different on different servers. I tried on my development workstation which is a Windows XP + Eclipse 3.3 + Tomcat 6 + Java 1.6 and my production server which is a Linux RH + Tomcat 6 + Java 1.6. They all work very well and so far I am OK with it hard coded.
Tuesday, February 03, 2009
For-Each Loop
for(Type type : types) {
... type ...
}
The For-Each loop makes Java code much more beautiful and clean than before. We shall use it any time we can.
Several exceptions,
... type ...
}
The For-Each loop makes Java code much more beautiful and clean than before. We shall use it any time we can.
Several exceptions,
- The program needs access to the iterator in order to remove the current element. The for-each loop hides the iterator, so you cannot call remove. Therefore, the for-each loop is not usable for filtering.
- Similarly it is not usable for loops where you need to replace elements in a list or array as you traverse it.
- Finally, it is not usable for loops that must iterate over multiple collections in parallel. These shortcomings were known by the designers, who made a conscious decision to go with a clean, simple construct that would cover the great majority of cases.
Subscribe to:
Posts (Atom)