Using Twitter BootStrap In Eclipse

This tutorial will assume that you have already installed Eclipse and its up and running. That said and done, lets get started shall we!

Step 1

We have to download twitter boot strap from BootStrap download . Boot strap is a front-end framework for faster and easier web development. It comprises of HTML, CSS and JS. It is made for folks of all skill levels, devices of all shapes and project of all sizes. Continue reading “Using Twitter BootStrap In Eclipse”

Advertisements

The Legacy: When Someone You Know Becomes Someone You Knew

The greatest legacy one can pass on to one’s children and grandchildren is not money or other material things accumulated in one’s life, but rather a legacy of character and faith. ~ Billy Graham

Life is gift from God, living is a blessing but death is inevitable for all of us. The way I see it, there comes a time in one’s life to ask some hard question.Especially when one loses people so close to them. Question like, Am I a good brother or sister? Am I a good son or daughter? What have I done to make the world a better place than I found it? What will I be remembered for? What will be my legacy?

I have always be inspired by people who have left legacy that will go beyond more than one generation. People like the lateNelson Mandela, Mother Teresa, Pro. Wangari Maathai to mention but a few. It is breathtaking that these ordinary people lived extra-ordinary life, full of sacrifices to ensure that life will be better for the next generation. I will always cerebrate individuals who created a remarkable legacy.

I have often pondered over some of the question above. Am I a good brother? Am I a good friend? Am I good son? Will I be a good husband? Will I be a good father? In life, maybe it is the little things that matter most. Things like family, friends and community. I have discovered that people will forget what you did for them, people will forget what you said but people will never forget how you made them feel.

I pray to God everyday, to give me many years to live but when it finally comes my and I get to the other side of life, I will find myself a bench if they got any. I would like to see the legacy I created change life in a positive way. Things like:

  • I was a good son to my mum.
  • I was good brother to my sister.
  • I was a good husband and a good father.
  • I played a role in development of one or two less privileged people.

Our world is vast in every way, we don’t know what tomorrows brings but having hope is paramount. The bad news is, the world is full of bad people and the good news is, the world is full of good people. People must learn to hate and if they can learn to hate, they can be taught how to love. Loves comes more natural to the human heart than its opposite.

Personally, I will try to create a legacy that is full of goodness. The one that give hope to the hopeless. The one that will inspire people around me. The one that my children will be proud off. I have discovered that the best legacy I can create is not to my children but in my children.

What will be your legacy?

I See A Ray of Hope

When I was about seven or eight years old, I could lay out on the grass, skid on the mad, play different games with my friends but the one I love most was “Cha Baba na Mama” meaning father and mother. What happened was that a boy and girl would play the roles of father and mother respectively. The reason I loved this game was because I got to choose the girl I liked.

We used to live in place where there was a small stream and some of my beautiful memories goes back in those good old days, when I used to walk with my late father along the stream. I used to call him “Dad” and I would here another voice repeat what I just said. It was confusing to me but not to my father. One day I asked him who was repeating my words and he said, “Son, that is an echo.”

Life can be boring at times, but if you have a partner who is vivacious, energetic, adventurous and full of life, they can help turn dull moments into lively ones. For me, my father was that kind of partner. That was a good life but now since I am a little bit older, different subject. It is in human nature to improve our lives in a positive way. To have things like successful careers, a good family to mention but a few.

Over the past few years, I have learnt that I still have a lot to learn. But just like when I was kid calling out my dad name, today is no different. In life, what you give is what the world will echo back to you. For example:

  • If you give love to the world, the world will echo back to you, the love you give in unexpected ways.
  • If you give hope to the people around you, hope will come back to you when you least expect it.
  • If you give a helping hand to the poor, someone will give you a helping hand when you hit rock bottom.

In life, there will always be ups and downs but I am more hopeful that better days are yet to come. What gives me hope is my mum, sister and my friends. What gives me hope is the fact that Hailey, a young girl in 2012 at only age six, she started to grow food for the homeless in her community. What gives me hope is the fact that education to girls is becoming more important and this promote gender equality. What gives me hope is the fact that life we will be better for all of us if we only work hard, because the universe throws opportunities every second and in all direction, including yours.

What gives me hope is the fact that, there is access to education to the poor thanks to donors. I am grateful to the people of who have invested in me. At the end of the day, they are people of good will who always try to make life better for others. Now that gives me hope.

From the depth of my being, I have discovered that people will forget what you said, people will forget what you did but people will never forget how you made them feel. Be a giver of hope, just like my childhood echo memories, echo success, echo prosperity and most importantly, make the world a better place to live in, wherever you are.

We have not taken the final step of our journey, but the first step on longer and difficult road to success. We will make mistake along the way but I couldn’t be more hopeful. The future is bright, doors of opportunities will open and life will be better.

I believe in a hope that a new hope is dawning. I believe that my dreams will come true. I believe in the promise of brighter tomorrows. I see a ray of hope.

How To Set up Cookies With Servlet

Talk is cheap. Show me the code. ~ Linus Torvalds

A browser cookie is a small piece of data sent from website and stored in user’s web browser while the user is browsing a given website. Every time user loads the website, browser sends the cookie back to the server to notify the website of the user’s previous activity.

We are going to learn how to set up cookies with servlet. We are going to create three files:

  • HelloForm.java (servlet).
  • HelloForm.html
  • ReadCookie.java (servlet).

Creating the first Servlet which is HelloForm.java, here is the code:

Servlet 1

Creating HelloForm.html here is the code

html

Now I want you to run HelloForm.html on your server and you will get something like this:

output

Now I need you to enter First Name and Last Name. After that, click submit. Now we need a way to read the stored names. I am going to use First Name as Henry and Last Name as Mbugua. Lastly, we will create Servlet to read our names.

Creating ReadCookie.java, here is the code:

readcookie

Now we will run ReadCookie.java in our server and see if we can read our stored names. Here is my result:

result

Have something to add, leave me a comment. Happy coding!

Client Request Servlet Demonstration

Good code is its own documentation. As you are about to add a comment, ask yourself, ‘How can I improve the code so that this comment isn’t needed?’ ~ Steve McConnell

When a browser requests for a web page, it sends lot of information to the web server which can not be read directly because this information travel as a part of header of HTTP request. Following is the example which uses getHeaderNames() method of HttpServletRequest to read the HTTP header
information. This method returns an Enumeration that contains the header information associated with the current HTTP request.

Once we have an Enumeration, we can loop down the Enumeration in the standard manner,
using hasMoreElements() method to determine when to stop and using nextElement() method to get each parameter name. Here is the code.

client

Once you are done creating the servlet with the above code, run it in you server and if everything goes right you should get the following result depending on your system.

header

Writing our first Servlet: Hello World

Programs must be written for people to read, and only incidentally for machines to execute ~ Abelson

Servlet are Java classes which service HTTP request and implement the javax.servlet.Servlet interface. Web application developers typically write servlets that extend
javax.servlet.http.HttpServlet, an abstract class that implements the Servlet interface and is specially designed to handle HTTP requests

In our previous lesson we learnt how to link eclipse and web container and now we are ready to create our first Servlet program. I am going to show how to create a dynamic project and a servlet that say Hello World.Launch your eclipse, click on file and choose Dynamic Web Project. You will get a screen like the one shown below:

1

In the project name put henry tutorial. Do not change anything else and click finish. In project explorer, your project will look like this:

2

When you create a servlet it is supposed to go to Java resources. So to create our Hello world servlet. Select Henry Tutorial and right click on it and proceed to new. Click on the servlet and you you will get the following screen.

3

In the Java package put com.henrymbuguakiarie and class name put HelloWorld. So you have the following screen.

4

After you are done with changes click finish and you servlet will open in eclipse editor.

5

Put the code in the image above in your servlet and click save.
Now I want you to go back in your project explorer and expand your project tree like this:

6

To run our HelloWorld.java we need to right click on it select Run As and select Run on Server. If you are successful you will have the following result.

7
Congratulations, you just created your first servlet. Wishing you happy codding.

NB:If you get a server error while running your servlet. The problem could be your server start services when you boot your computer. The solution is to stop your server and run the servlet again. Am a Linux user, just launch your terminal and key in the following command to stop your server.
Sudo service tomcat6 stop. Go back to eclipse and run HelloWorld.java on the server.