Freely Scripted Soul

November 24, 2007

Using Servlets in Fedora Core 3

Filed under: Software and Technology — Roshan @ 9:21 am
Tags: , , , ,

All commands and descriptions are CASE SENSITIVE

 

 

STEP 1: INSTALLATION

 

 

First of all, while installing Fedora, be sure to tick the optional packages of “Web Servers” and “Mysql Servers” (or after installation, boot from your CD and “upgrade” your system by selecting the required packages).

Download Java6 and Apache-Tomcat5.5.

Copy both the downloaded files – “jdk-6u3-linux-i586.bin” and “apache-tomcat-5.5.25.tar.gz” – to “/opt”.

Install Java6 and Apache-Tomcat5.5 by running the following commands at the terminal:

$ cd /opt

$ ./jdk-6u3-linux-i586.bin

$ tar -xvzf apache-tomcat-5.5.25.tar.gz

 

 

STEP 2: SETTING UP

 

 

Create symbolic links for the “java” and “tomcat” folders in “/opt” only by running these commands at the terminal:

$ ln -s apache-tomcat-5.5.25 tomcat

$ ln -s jdk1.6.0_03 java

Edit the “profile” file using the following command:

$ gedit /etc/profile

A file will open with the a number of lines in it. Append the following lines in it:

export JAVA_HOME=/opt/java

export CATALINA_HOME=/opt/tomcat

export CLASSPATH=.:/opt/tomcat/common/lib/servlet-api.jar

PATH=$PATH:$JAVA_HOME:$CATALINA_HOME:$CLASSPATH:.

Save and close the file.

Download this web.xml file to your HOME folder (or change your directory to the folder in which you have stored this downloaded file), rename it as “web.xml” and copy it to the folder “/opt/tomcat/conf”:

$ cp web.xml /opt/tomcat/conf/

Setup is done.

 

 

STEP 3: RESTART

 

 

Go to Applications->System Settings->Server Settings->Services

The “Services” window will open. On the left-side pane, one-by-one, “tick” the boxes and click on the “Start” button for the following services: httpd, mysqld

You should get appropriate messages that the services have been started successfully.

Click on the “Save” button to save these settings permanently.

Restart the system for the changes to take effect.

 

 

STEP 4: TESTING

 

 

Run this command at the terminal to start Tomcat: (This has to be done each time you start a new session i.e. each time you login and want to use Tomcat)

$ sh /opt/tomcat/bin/startup.sh

The output will show the Tomcat’s environment variables and their values.

To test whether Tomcat has been set up properly, open this link in the browser:

http://localhost:8080

If you get the Apache Tomcat Homepage, it means that Apache and Tomcat has been set up properly.

To check whether Servlets has been set up properly, open this link in the browser:

http://localhost:8080/servlets-examples/

It opens the Servlets examples page of Apache Tomcat. Run the examples on the page. If they execute properly, Servlets have been set up properly.

Copy the source code of the example “Hello World” there. Open a file in your home folder:

$ gedit HelloWorld.java

Paste the contents of the example in this file. Save and close the file.

Compile this file:

$ javac HelloWorld.java

If it doesn’t give any errors and the byte-compiled “.class” file is created, then Java has been set up properly.

 

 

STEP 5: USING

 

 

Run this command at the terminal to start Tomcat: (This has to be done each time you start a new session i.e. each time you login and want to use Tomcat)

$ sh /opt/tomcat/bin/startup.sh

The output will show the Tomcat’s environment variables and their values.

Run this command at the terminal:

$ mkdir /opt/tomcat/webapps/ROOT/WEB-INF/classes

(If it already exists, no problem!)

Store all your “.java” and “.class” files in this “classes” folder.

For example:

$ cd /opt/tomcat/webapps/ROOT/WEB-INF/classes

$ gedit HelloWorld.java

A file will open. Write your Servlet code in it. Save and close the file.

$ javac HelloWorld.java

Now to run this Servlet, open this link in your browser:

http://localhost:8080/servlet/HelloWorld

This should work provided your Servlet code is right.

Now, suppose you want to write a HTML file which will use your Servlet program. Then you need to store it in your “ROOT” folder of Tomcat.

For example:

$ cd /opt/tomcat/webapps/ROOT

$ gedit HelloWorld.html

A file will open. Write your HTML code in it, which will interact with “HelloWorld.class” file in the “classes” folder. Save and close the file.

Open this link in your browser:

http://localhost:8080/HelloWorld.html

This should work provided your HTML code is right and provided your Servlet code in the “classes” folder has been byte-compiled(“.class” file).

 

DOWNLOAD LINKS:

Java6 – https://sdlc4a.sun.com/ECom/EComActionServlet;jsessionid=87D3A2EB1CF3330672A9619B88690488

“Accept” License Agreement and click on Linux self-extracting file “jdk-6u3-linux-i586.bin”.

Apache-Tomcat5.5 – http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/

 

 

 

Click on “apache-tomcat-5.5.25.tar.gz “.

Web.xml – http://www.esnips.com/doc/128015cf-4006-48b9-a640-dcd6db5b7748/web-fedora3

 

 

PS: If something doesnt work, please check for missing or erroneous case-sensitive letters or slashes. If you face some problem and are unable to find a solution, feel free to add a comment here or mail me. I ll do my level best to find a solution.

 

 

PPS: Thanks to Madhusudan C S for the wonderful research 🙂

 

Advertisements

6 Comments »

  1. I was searching for this kind of a blog for months now. Actually lost the hope of finding one, but here i am 🙂 Thanks for the great articles! Looking forward for a little read after dinner 🙂

    Comment by daily interesting — November 26, 2007 @ 12:19 pm | Reply

  2. my pleasure 😀

    Comment by Roshan — November 27, 2007 @ 1:38 am | Reply

  3. i didnt install it yet… it was too confusing at start.. the cd installation was a pain..

    i prefer soem easier installation process…

    Comment by SUPREETH — November 27, 2007 @ 4:52 am | Reply

  4. huh.. did u install ubuntu?????
    its as easy as installin windows, if not easier!! 😉
    you just to create a separate partition for ubuntu, preferably manually, during the installation process!!

    Comment by Roshan — November 28, 2007 @ 1:35 am | Reply

  5. i have fecore 6 . tell me wat to do… ll install in hols..

    Comment by Supreeth Rajan — January 6, 2008 @ 4:16 am | Reply

  6. hey supreeth, i dunno about fedora much!! i use ubuntu.. oly things in fedora which are similar to ubuntu, i mite be able to tel u.. i wud suggest u to begin wit Ubuntu any version..

    Comment by Roshan — January 14, 2008 @ 2:59 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: