Creating Google gadgets with GWT

Create a new GWT/AppEngine project

Modify SimpleGadget.gwt.xml file:

xml version="1.0" encoding="UTF-8"?>
DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "">
<module rename-to='simplegadget'>

<inherits name="" />
<inherits name="" />
<inherits name="" />
<stylesheet src="hello.css" />

<entry-point class='com.taktico.simplegadget.client.SimpleGadget'/>


package com.taktico.simplegadget.client;


@ModulePrefs(title = "SimpleGadget", author = "Uki D. Lucas", author_email = "")
public class SimpleGadget extends Gadget
protected void init(UserPreferences preferences)
RootPanel.get().add(new Label("Hello World!"));

Modify SimpleGadget.html

DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="SimpleGadget.css">
<title>Web Application Starter Projecttitle>
<script type="text/javascript" language="javascript" src="simplegadget/simplegadget.nocache.js">script>

Add gwt-gadgets.jar to your project

Compile the project

Post (deploy) the compiled directory on the Web (e.g. iDisk)

Open iGoogle -> Add Stuff -> Add feed or gadget -> paste your deployed gadget URL

Finished SimpleGadget in iGoogle

Azim Premji - "My Lessons in Life"

An Article Address by Azim Premji in the "Shaping Young Minds Program" (SYMP) organized by AIMA in collaboration with the Bombay Management Association (BMA) in Mumbai on "My Lessons in Life".

I am very happy to be here with you. It is always wonderful to be with young people. As my hair turned from black, to salt and pepper and finally salt without the pepper, I have begun to realize the importance of youth. At the same time, I have begun to truly appreciate some of the lessons I have learnt along the way. I hope you will find them useful when you plan your own career and life.


The first thing I have learnt is that we must always begin with our strengths. There is an imaginary story of a rabbit. The rabbit was enrolled in a rabbit school. Like all rabbits, it could hop very well but could not swim. At the end of the year, the rabbit got high marks in hopping but failed in swimming. The parents were concerned. They said, "Forget about hopping. You are anyway good at it. Concentrate on swimming." They sent the rabbit for tuitions in swimming. And guess what happened? The rabbit forgot how to hop! As for swimming, have you ever seen a rabbit swim? While it is important for us to know what we are not good at, we must also cherish what is good in us. That is because it is only our strengths that can give us the energy to correct our weaknesses.


The second lesson I have learnt is that a rupee earned is of far more value than five found. My friend was sharing me the story of his eight year-old niece. She would always complain about the breakfast. The cook tried everything possible, but the child remained unhappy. Finally, my friend took the child to a supermarket and brought one of those ready-to-cook packets. The child had to cut the packet and pour water in the dish. The child found the food to be absolutely delicious? The difference was that she has cooked it! In my own life, I have found that nothing gives as much satisfaction as earning our rewards. In fact, what is gifted or inherited follows the old rule of come easy, go easy. I guess we only know the value of what we have if we have struggled to earn it.


The third lesson I have learnt is no one bats a hundred every time. Life has many challenges. You win some and lose some. You must enjoy winning. But do not let it go to the head. The moment it does, you are already on your way to failure. And if you do encounter failure along the way, treat it as an equally natural phenomenon. Don't beat yourself for it or any one else for that matter! Accept it, look at your own share in the problem, learn from it and move on. The important thing is, when you lose, do not lose the lesson.


The fourth lesson I have learnt is the importance of humility. Sometimes, when you get so much in life, you really start wondering whether you deserve all of it. We have so much to be grateful for. Our parents, our teachers and our seniors have done so much for us that we can never repay them. Many people focus on the shortcomings, because obviously no one can be perfect. But it is important to first acknowledge what we have received. Nothing in life is permanent but when a relationship ends, rather than becoming bitter, we must learn to savor the memory of the good things while they lasted.


The fifth lesson I learnt is that we must always strive for excellence. One way of achieving excellence is by looking at those better than ourselves. Keep learning what they do differently. But excellence cannot be imposed from the outside. We must also feel the need from within. It must involve not only our mind but also our heart and soul. Excellence is not an act but a habit. I remember the inspiring lines of a poem, which says that your reach must always exceed your grasp. That is heaven on earth. Ultimately, your only competition is yourself.


The sixth lesson I have learnt is never give up in the face of adversity. It comes on you suddenly without warning. Always keep in mind that it is only the test of fire that makes fine steel. A friend of mine shared this incident with me. His eight-year old daughter was struggling away at a jigsaw puzzle. She kept at it for hours but could not succeed. Finally, it went beyond her bedtime. My friend told her, "Look, why don't you just give up? I don't think you will complete it tonight. Look at it another day." The daughter looked with a strange look in her eyes, "But, dad, why should I give up? All the pieces are there! I have just got to put them together!" If we persevere long enough, we can put any problem into its perspective.


The seventh lesson I have learnt is that while you must be open to change, do not compromise on your values. Mahatma Gandhiji often said that you must open the windows of your mind, but you must not be swept off your feet by the breeze. Values like honesty, integrity, consideration and humility have survived for generations. At the end of the day, it is values that define a person more than the achievements. Do not be tempted by short cuts. The short cut can make you lose your way and end up becoming the longest way to the destination.


And the final lesson I learnt is that we must have faith in our own ideas even if everyone tells us that we are wrong. There was once a newspaper vendor who had a rude customer. Every morning, the Customer would walk by, refuse to return the greeting, grab the paper off the shelf and throw the money at the vendor. The vendor would pick up the money, smile politely and say, "Thank you, Sir." One day, the vendor's assistant asked him, "Why are you always so polite with him when he is so rude to you? Why don't you throw the newspaper at him when he comes back tomorrow?" The vendor smiled and replied, "He can't help being rude and I can't help being polite. Why should I let his rude behavior dictate my politeness?

I hope you achieve success in whatever way you define it and what gives you the maximum happiness in life. "Remember, those who win are those who believe they can."

Calling JSP from a batch file

If you wondering why in the world should I call a JSP from a batch file then read on. In fact, my problem was to schedule a task that runs every day on a specific time and must generate a report for my management and email the same. Searching the net I was able to accomplish this by combining VB and batch files. But I was not happy with the results. Or to be more specific, my management was not happy with the type of report I was generating in terms of formatting etc.

What the management wanted was a nicely formatted report just as our internal WEB based reports. Now I realised that I have already a JSP that generates the report, now I only have to do two things.

1. Modify the JSP to instead of displaying, just generate the report in HTML format and then email it
2. Secondly I must find a way to schedule this emailing to auto email every day at a specific time.

So I have answered the question as to the necessity of calling a JSP from a batch file. Now that I have decided on what to do, I set search on how to do this. Then I found that batch file by itself cannot accomplish this, therefore I would need a combination of a batch file and a vbscript file (VBS).

So assuming you have a JSP page that generates the report and emails it. Do the following to automate the report generation:

1. Create a text file and copy the following content into it:

Option Explicit
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "" (This should be changed to your actual url)
objIEA.visible = true
While objIEA.Busy
Set objIEA = Nothing

2. Rename the text file to report.vbs

3. Create a batch file and name it as report.bat and copy the following content in that batch file.

cscript.exe report.vbs

4. Create a Scheduled task from windows or cron job in your Unix servers to call this report.bat as per your requirement.

How to read and write in file through JSP

<%@ page import="*" %>

Read write file JSP

String fileName=getServletContext().getRealPath("jsp.txt");

File f=new File(fileName);

InputStream in = new FileInputStream(f);

BufferedInputStream bin = new BufferedInputStream(in);

DataInputStream din = new DataInputStream(bin);
StringBuffer sb=new StringBuffer();

try {
PrintWriter pw = new PrintWriter(new FileOutputStream("c:/file.txt"));// save file
} catch(IOException e) {

Successfully write file

Java Servlet to Write to a temporary file

* Write to a temporary file
* @author Sanjeev Kulkarni
* @since 0.5 - 18-Nov-2009 3:23:35 PM
* @version 0.1

package com.ack.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WriteToATemporaryFile extends HttpServlet {

public void doGet( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException {
// get the web applications temporary directory
File tempDir = (File) getServletContext().
getAttribute( "javax.servlet.context.tempdir" );

// create a temporary file in that directory
File tempFile = File.createTempFile( getServletName(), ".tmp", tempDir );

// write to file
FileWriter fw = new FileWriter( tempFile );
try {
fw.write( "done and dusted" );
finally {

// tell servlet client where to look for file
res.getWriter().println( "check file: " + tempFile.getAbsolutePath() );