Wednesday, March 21, 2007

Manually Deploying A New Tomcat Web Application ...continue

As promised in my last post, i will describe the process of writing and deploying servlets on Tomcat.

Servlets are java classes which can handle HTTP request and send dynamic response back to the client. Unlike JSP pages, servlets have to be compiled by the developer, wherese JSP pages are first transformed to servlet source files by JSP engine and then compiled to servlet classes by the servlet engine. The advantage of servlet over JSP is they need no compilation time for first time as required by JSP pages.

When deploying a Servlet class we have to put the class file in pre-defined "classes" directory which has to be under the "WEB-INF" directory. We can also put the source file there.

Here is a simple servlet source file, save it as HelloServlet.java under "WEB-INF\classes" directory.

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
* The simplest possible servlet.
*
* @author Put Your Name Here
*/

public class HelloServlet extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");

out.println("<title>Hello World Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("Hello World!, I am a servlet");
out.println("</body>");
out.println("</html>");
}
}

Before compiling the servlet we have to set our CLASSPATH correctly. To compile a servlet, the JAR file "servlet-api.jar" containing the required classes has to be in our classpath. It is generally found at "common\lib" directory under Tomcat installation directory. We can either set it in our environment variable or we can declare it in command-line.

Now, we will goto command prompt and compile the servlet using the following command.

D:\tomcat5\webapps\app1\WEB-INF\classes>javac -classpath %CLASSPATH%;D:\tomcat5\common\lib\servlet-api.jar HelloServlet.java

This will generate a class file "HelloServlet.class" in the same directory. But, the work is still not over. We have to inform Tomcat about this servlet through our applications configuration file which is "web.xml".

So, add the following lines in web.xml between the tags <web-app></web-app>.



<servlet>

  <servlet-name> HelloServlet </servlet-name>

  <servlet-class> HelloServlet </servlet-class>

</servlet>



<servlet-mapping>

  <servlet-name>HelloServlet</servlet-name>

  <url-pattern>/Hello</url-pattern>

</servlet-mapping>


The contains of <servlet></servlet> tags define a servlets name ands its corresponding class by using the <servlet-name> and <servlet-class> tag. The contains of <servlet-mapping></servlet-mapping> tags define the URL which is mapped to the servlet class. It is required because when a client request a servlet class, it cannot be directly send to the client. So when a client request an URL which point to a servlet Tomcat server executes the servlet for the client and send the output back to the client. The <servlet-name> is used for identifying the servlet and the <url-pattern> tag is used to inform Tomcat that when any request for this URL arrives, executes this servlet and send its output back to the client.

Now, we are ready to test the servlet. Start Tomcat server and point our browser to the URL http://localhost:8080/app1/Hello.

Tuesday, March 20, 2007

Manually Deploying A New Tomcat Web Application

Tomcat is the first choice for all students,like me, who have started learning JSP or servlet. But again like me, many students finds it hard to get started with it as there is no in-built tool for deploying a new application in Tomcat. So in this post i am sharing my little experience on starting a new Tomcat web-application.

First of all we have to be familier with the directory structure of tomcat. In my computer Tomcat 5.5 is installed at D:\tomcat5. Under it there are 9 directories.

a) bin - all executables and the main starting point of Tomcat server
b) conf - all configuration files
c) log - all Tomcat log files
d) temp - for temporary use by Tomcat
e) common - all common use compiled java classes
f) server - all classes required to run the Tomcat server
g) shared - all classes shared by Tomcat and any other web-applications
f) work - used by Tomcat as its working directory, all applications are served form this directory
g) webapps - default folder to store web applications

among the above said, we are mainly interested in the last directory i.e. webapps.

To start a new application create a new folder under the webapps directory. Lets say we want start a application named "app1". So create a directory "app1" under "webapps". Then put all the JSP and HTML files under it.

Now at least one more directory need to be created under "webapps" and it has to be named "WEB-INF". The "WEB-INF" directory should contain a XML file named web.xml which is used as the configuration file of our appliocation. Here is a minimum web.xml file.


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>

</web-app>

Save this as web.xml under the "WEB-INF" folder. Now we will create a JSP test page.

Save the following lines as "index.jsp" under "app1" directory.


<html>
<head>
<title>Testing Tomcat</title>
</head>
<body>
<% out.println("Hello, World! I am a JSP Page"); %>
</body>
</html>


So, after all this our directory structure should be like this

D:\tomcat5
 - webapps
   - app1
    - index.jsp
    - WEB-INF
     - web.xml

Now start Tomcat and locate our browser to the address "http://localhost:8080/app1/"

Wrintng and deploying a servlet requires a little more work. So to keep things simple i will describe that in another post.

Wednesday, December 20, 2006

What Metora/LP Song are you?







What Linkin Park\Meteora Song Are You?




You are track #3, Somewhere I Belong
Take this quiz!







What Matrix Persona are you?








What Matrix Persona Are You?







You are Neo, from "The Matrix." You display a perfect fusion of heroism and compassion.


Take this quiz!


Sunday, November 12, 2006

Tux got an X-35

Few days ago RedHat Inc. gets a nasty blow from Database Major Oracle Corp. Oracle announces that it will provide support for RedHat products for half the price of RedHat. Oracle says it has 7,000 employees in support services alone while Red Hat says it employs a companywide total of 1,800. After this news stock price of RedHat shares have fallen half of that before.

But, Dennis Kekas, director of North Carolina State University's Network Technology Institute, which has a close relationship with Red Hat, said the company will have no trouble thriving in the ever-expanding open source market. "There's a lot of room out there for a lot of players to participate in the open source movement," Kekas said. "Red Hat's just too sophisticated and too strong to be threatened. They have built such a strong reputation."

Fox News: http://www.foxnews.com/story/0,2933,225925,00.html

In another strategic play Microsoft CEO Steve Ballmer said that his sales team will offer its corporate customers a chance to license its Windows operating system as part of a package offering maintenance and support for Novell's Suse Linux platform. Apparently, the goal is to make Linux interoperable with Windows and perhaps move some apps onto the Linux platform. Microsoft agreed not to sign a similar agreement with any other Linux distributor for three years. Microsoft's pact with Novell dealt a blow to other Linux distributors such as market leader Red Hat Inc. For this agreement Microsoft will make two separate up-front payments totaling $348 million to Novell.

It seems that Steve Ballmer has a better foresight then Bill Gates, that's why he has been able to take the decision inspite of the fact that in 2004, Novell reached a $536 million settlement with Microsoft over antitrust complaints in Europe and then sued its rival again in the United States. The U.S. suit alleged that Microsoft withheld technical information about Windows that Novell needed for its word processing program WordPerfect which has been sold to Microsoft.

Fox News: http://www.foxnews.com/story/0,2933,227297,00.html

Both this news reflects the increasingly important role of Linux open-source software in corporate computing systems. About 20 percent of corporate America relies on some form of Linux. Because it's available for free, Linux software long has been has been a source of consternation for Microsoft, which makes most of its money from the sale of its proprietary software. As now major software companies are eager to providing support for Linux, many problems that previously made the advancements of Linux in the market slower will be removed. Such a problem was regarding technical information about various Hardwares from manufacturer's which is required for developing Linux device drivers. It is just a start and we don't have to wait very long when every server system will be powered by Linux including major part in Desktop market.

Tuesday, October 17, 2006

"M$ Vista: New Features", are they really new ?

Here are some "New Features" of M$ Vista operating system as shown in Vista website at

http://www.microsoft.com/windowsvista/features/default.mspx

::User Experience::

a) integrated desktop search with instant search (is it anyway faster/ newer then slocate in Linux
except a nice looking GUI ?)

b) Live Icon in new Explorer (i think i am quite accoustomed to this in GNOME & KDE)

c) Command Bars show Context Sensitive Tasks depending on file type (You have to check old versions of RedHat to know when it was implented in Linux)

d) Windows Vista Aero provides spectacular visual effects such as glass-like interface elements that you can see through (Adjust the Transparency level in KDE and see what you got)

e) Live Taskbar Thumbnails

f) Windows Flip & Filp 3D

::Security::

a) A PC protected from viruses, worms, spyware, and other potentially unwanted software (Same old unkept promise of NT, lets see what happen to this one)

b) User Account Control (Never dare to think of M$ catching Linux in this field, anyone heard of "sudo" in Linux)

c) No Virus in Vista, very good, but then why this...

"In addition to using these built-in Windows Vista features, you should help keep your computer healthy by using antivirus software such as Windows OneCare or an antivirus solution from one of Microsoft's partners. Whichever option you choose, remember to update your antivirus software regularly. These updates are generally available through a subscription from your antivirus vendor."

Source: Better protection from malware
http://www.microsoft.com/windowsvista/features/foreveryone/security.mspx

Follow the last line in the qoute...

::IE 7::

really cant remember when Mozilla,Opera implemented these features

a) Tabbed Browsing
b) Built in RSS Reader
c) Protected/Author Mode browsing (check out the full list in Opera, cant type all modes here, list is long)

::Performance::

a) SuperFetch : preloads most used applications into memory
b) ReadyBoost : use USB drives as RAM
c) ReadyDrive : flash hard-drive(also called hybrid HD) support

Many OSS device driver developers has to develop their product without full khnowladge the hardware specification as the "Vendors" charge a huge amount to provide the specification.
They have to use reverse engineering to "guess" the specifications. Still hardware support is not way behind in Linux. If someone thinks that Linux has loosed this field, just wait a while before making any comments.

::Networking::

Network Map (Nothing new for me atleast)

::Gadgets & Sidebar::

Do you know what a NewsTicker, PersonalNotes and a hell lots of free small utilities (called applets) and many like that does in KDE & GNOME?


Now, the point is that I am not against Vista or M$, but the main fact is that Vista is niether the only nor the best OS in this world. The defination of Best is relative to somebody, for me the OS that will give me normal look and features with maximum performance through proper utilisation of limited resource is best. But it is perfectly justified for somebody to choose one with the catchy outlook and superb presentation as the best.

Till now i am a user of XP, Debian and Fedora and i never look down on any of them, because where one loose the other wins.

For more information on M$ Vista check out this link...
http://www.winsupersite.com/showcase/winvista_preview_2005.asp

Thursday, October 05, 2006

whoami ?

Yes, this is a Linux command which gives information about the Host the user is connected to. But why a Linux command in someone's first blog...

because now you are going to get some information about the owner of the blog you are reading to...

so, this is Chandan Chowdhury who call him self the i_virus...

he is a final year Computer Science student now in Asansol Engineering College. He call himself i_virus becuase "i" is for himself and "i" is for India and "virus" because something like a computer virus he has very little existence or life without a computer... thats why the combo... i_virus

from now on he will share his views, his khownladge(yes, though very little he has some knowladge which may seems bogus to you) with you...

so please have a eye over here...