Oct 13, 2007

Eid Mubarak...

And again another Eid has come today !! It's the first Eid after I have started my carrer, so it's very special for me. It's again the same old routine for Eid day....get ready with new dress & ornaments, visit all relatives , and after a whole day of gossiping and eating, seat before the TV , try to watch "SPECIAL" rubbish programmes !

In every other country, people get discount on purchase in occasion of festival, but as we are Bangladeshis, we ought to be exceptional, so we raise the price of everything, specially things that are essential in Ramadan. We don't even complain for this anymore, that's our own way !
The streets of Dhaka is quiet and traffic-jam-free for these few days as many people have left the city to meet their near and dear ones, yesterday I went to the mall with my sister , mom was away with her sisters...ya we had our fun while they have theirs ! Anyway, Eidee is another unmissable part of Eid, this time , as I have my own job now, I think I cannot escape from giving Eidee to my little cousins..so I have kept aside new bundles of notes for them, hope they spare me for little amount.

When I was younger , I used to get up in the roof along with my sisters and cousins
to see the new moon which brings the message of Eid. And dressing up with new clothings was trully a matter of rejoicing that time. Children are so blessed with the power of being happy with every little bliss Allah has bestowed upon us !! So lucky they are !!!

Whatever, still Eid is really a wonderful part of our life, don't know why, whether I enjoy the Eid day or not, the very thought brings a rush of joy in mind, all the month-long preparation , all these long9ing just for one day, however boring or interesting that day really happens to be, the excitement of preparing for Eid never looses its charm !

We try to keep a smiling face all day long, try to serve every one with the very best of hospitality, to show everyone that we are as happy as them (or even more )! Not a single trace of cobweb in wall, no dust in the furniture, no disparage in expression, no harshness in speech; Everything seems so perfect, so colourful, like we have nothing more to want for !!!

And when the day is past, again we return to ourselves, return to the real world, our weary , exhausted world , waiting for another Eid to come !

Oct 12, 2007

struts ,jsp,mysql with unicode support

jsp, mysql, struts with unicode character set support should have been an easy task, I found ample reference in web, still I had to face a lot of complications while setting up a website ( jsp based )which can take Bangla ( a unicode character set ) input from users, process the input via struts framework, store it in MySQL database and again display them in the same website. For Bangla text, it must have unicode support in the JSPs . The underlying database is mysql and we have used Struts to implement the MVC architecture. Our task was to provide it character set UTF-8 support in every layer.
Now I describe what we really done to make it :

Make the database Unicode compatible:

MySQL’s default character encoding is Latin1. We have to change it to utf-8 for Unicode compatibility.
    • Install mysql 5, if any previous version is already installed, first uninstall it.
    • If you need the data already inserted n the database, don’t forget to keep the backup. Dump it to a file using mysqldump. We here call the file dump.sql.
    • Every database has a database character set and a database collation.
    • The CREATE DATABASE and ALTER DATABASE statements have optional clauses forspecifying the database character set and collation:
[[DEFAULT] CHARACTER SET charset_name]
[[DEFAULT] COLLATE collation_name]

[[DEFAULT] CHARACTER SET charset_name]
[[DEFAULT] COLLATE collation_name]

See for more ..
For example :

“Drop database dbname;”
“CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;”
    • Replace all latin1 instances with utf8 in the dump.sql file .
    • Load the dump into the new DataBase, run the script dump.sql. If you are creating a whole new database without using any previous data, then this step is not needed.

    • If you are uncertain about the character set or collation of the result returned by a string function, you can use the CHARSET() or COLLATE() function to find it.
    • For example:


dba@localhost| utf8 | utf8_general_ci |
    • Now the database is Unicode compatible , but the JDBC driver or database connector has to know it; so we have to tell it through the connection string. We have to append this with the connection string : useUnicode=true&characterEncoding=UTF-8”.
For example:

String username="root";
String password="";
String url=
try {
Class.forName("com.mysql.jdbc.Driver").newInstance(); this.connection=DriverManager.getConnection(url,username,password);
catch(ClassNotFoundException ex){}

Thus we are done with the database.

Page encoding:

this is for the jsp pages to recognize utf-8 and use unicode encoding, so that your browser knows that it should use the character set utf-8. Put the following line at the top of your page; it will ensure that the Content-Type header is set appropriately
<%@page contentType="text/html;charset=UTF-8"%>

To set page encoding to utf-8 , this is what you should write:

<%@page  contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
put the correct meta tags in your HTML pages:
  • meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 

If you're using forms, be sure to add this in the form:


As we are running the web application in Tomcat, it's better add the parameter
to Java options in catalina.bat/catalina.sh file to tell JVM that you are using utf-8.
Filter for Struts Action :

As I have already said that we are using Struts action for submitting our forms, we have to make sure that our encodings are intact through struts. The default character encoding of struts is iso-8859-1. So, we have to use this filter so all our request and response undergo this filter to view unicode character properly. To do this, just create a java class, suppose Filter.java .

public class Filter implements javax.servlet.Filter {

private FilterConfig filterConfig;
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig; }

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {



// Set the content type in the header of the response servletResponse.setContentType("text/html;charset=UTF-8");

filterChain.doFilter(servletRequest, servletResponse);
public void destroy() {}

Register this filter in web.xml file and define the mapping for this filter in web.xml file .

Hopefully this is all we need , still if anything goes wrong, don't worry, keep patience and think cool headed,

this is the lesson I learned while working in this project which now supports Unicode in all its layers.