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 🙂

 

November 18, 2007

Using Servlets in Fedora Core 7

Filed under: Software and Technology — Roshan @ 4:07 pm
Tags: , , , ,

All commands and descriptions are CASE SENSITIVE

 

 

STEP 1: INSTALLATION

 

 

First of all, install Java6, Apache, Tomcat5.5 and all related packages by using your installation DVD(while installing Fedora itself or after installation, boot from the DVD and “upgrade” your system by selecting the required packages).

NOTE: Tomcat is an optional package under “Web Servers”. So click on “Web Servers” and then on “Option Packages”. Browse the list and “tick” all Tomcat related packages.

 

 

STEP 2: SETTING UP

 

 

Edit the “.bashrc” file using the following command:

$ gedit $HOME/.bashrc

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

export JAVA_HOME=/usr/share/java

export CATALINA_HOME=/etc/tomcat5

export CLASSPATH=.:/var/lib/tomcat5/common/lib/[servlet].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 “/etc/tomcat5”:

$ cp web.xml /etc/tomcat5/

Setup is done.

 

 

STEP 3: RESTART

 

 

Go to System->Administration->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, tomcat5

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

 

 

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

 

 

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

/var/lib/tomcat5/webapps/servlets-examples/WEB-INF/classes

For example:

$ cd /var/lib/tomcat5/webapps/servlets-examples/WEB-INF/classes

$ gedit HelloWorld.java

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

$ javac HelloWorld.java

Before running it, you need to TWEAK the “web.xml” file. Run this command at the terminal:

$ gedit /var/lib/tomcat5/webapps/servlets-examples/WEB-INF/web.xml

Click on the “Replace” button or press “Ctrl+H” from the keyboard.

You need to replace all instances of “HelloWorldExample” with your filename i.e. “HelloWorld”.

So enter “HelloWorldExample” in “Search For” box and “HelloWorld” in “Replace with” box and click “Replace All”.

Save and close the file.

IMPORTANT: This TWEAKING is necessary for ONLY the first time you are executing a Servlet in your system. Once you tweak this file and execute your Servlet successfully, just FORGET about this file. (I don’t quite understand the logic behind this. It quite illogical! However, servlets work only if you tweak web.xml in this way! Maybe a bug in Fedora7 😉 )

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

http://localhost:8080/servlets-examples/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 “servlets-examples” folder of Tomcat.

For example:

$ cd /var/lib/tomcat5/webapps/servlets-examples

$ 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/servlets-examples/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 LINK:

Web.xml – http://www.esnips.com/doc/ca71aa2c-ec61-4fbb-8b0e-85a670ef6c2f/web-fedora7

 

 

 

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 Uday S Athreya for the wonderful research 🙂

 

Using Servlets in Ubuntu Gutsy Gibbon

Filed under: Ubuntu — Roshan @ 3:48 pm
Tags: , , , , ,

All commands and descriptions are CASE SENSITIVE

 

 

STEP 1: INSTALLATION

 

 

First of all, install Java6, Apache, Tomcat5.5 and all related packages:

 

Use Synaptic Manager(recommended)

OR

Run these following commands at the terminal:

$ sudo apt-get install apache2-mpm-prefork apache2-common apache2-utils

$ sudo apt-get install sun-java6-jdk tomcat5.5 tomcat5.5-admin tomcat5.5-webapps

$ sudo apt-get install libapache2-mod-jk

 

 

STEP 2: SETTING UP

 

 

Run this command at the terminal:

$ sudo a2enmod

Then a prompt for a module comes. There type “jk” and enter:

Module name? jk

Prompt comes back.

Edit the “jk.load” file using the following command:

$ sudo gedit /etc/apache2/mods-enabled/jk.load

A file will open with the following line in it:

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

Append the following lines in it:

JkWorkersFile /etc/apache2/workers.properties

JkLogFile /var/log/apache2/mod_jk.log

JkLogLevel debug

JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “

JkMount /jsp-examples worker1

JkMount /jsp-examples/* worker1

JkMount /servlets-examples worker1

JkMount /servlets-examples/* worker1

Save and close the file.

Edit the “workers.properties” file using the following command:

$ sudo gedit /etc/apache2/workers.properties

An empty file will open. There paste these contents:

workers.tomcat_home=/usr/share/tomcat5

workers.java_home=/usr/lib/jvm/java-1.5.0-sun

ps=/

worker.list=worker1

worker.worker1.port=8009

worker.worker1.host=localhost

worker.worker1.type=ajp13

worker.worker1.lbfactor=1

Save and close the file.

Edit the “environment” file using the following command:

$ sudo gedit /etc/environment

A file will open with the following lines in it:

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

LANG=”en_IN.UTF-8″

LANGUAGE=”en_IN:en”

Append the following lines in it:

CLASSPATH=.:/usr/lib/jvm/java-6-sun/bin:/usr/share/tomcat5.5/common/lib/servlet-api.jar

JAVA_HOME=/usr/lib/jvm/java-6-sun

Save and close the file.

Edit the “.bashrc” file using the following command:

$ gedit $HOME/.bashrc

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

export JAVA_HOME=/usr/lib/jvm/java-6-sun

export CATALINA_HOME=/usr/share/tomcat5.5

export CLASSPATH=/usr/share/tomcat5.5/common/lib/servlet-api.jar

export PATH=$PATH:$JAVA_HOME/bin:$CLASSPATH:$CATALINA_HOME

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 run this command at the terminal:

$ sudo cp web.xml /etc/tomcat5.5/

Setup is done.

 

 

STEP 3: RESTART

 

 

Restart Apache and Tomcat by running the following commands at the terminal:

$ sudo /etc/init.d/apache2 stop

$ sudo /etc/init.d/tomcat5.5 stop

$ sudo /etc/init.d/tomcat5.5 start

$ sudo /etc/init.d/apache2 start

Restart the system for the changes to take effect.

 

 

STEP 4: TESTING

 

 

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

http://localhost:8180

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:8180/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 servlet-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:

$ sudo mkdir /usr/share/tomcat5.5-webapps/ROOT/WEB-INF/classes/

(If it already exists, no problem!)

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

For example:

$ cd /usr/share/tomcat5.5-webapps/ROOT/WEB-INF/classes/

$ sudo gedit HelloWorld.java

PS: It is a MUST to use “sudo” before each command as this folder is “writable” only with administrative privileges(Instead of typing it each time, you can also use the super-user shell by running the command “su”)

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

$ sudo javac HelloWorld.java

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

http://localhost:8180/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 /usr/share/tomcat5.5-webapps/ROOT

$ sudo gedit HelloWorld.html

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

Open this link in your browser:

http://localhost:8180/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 LINK:

Web.xml – http://www.esnips.com/doc/997deb96-203b-42fd-85aa-755be8ca5244/web-ubuntu

 

 

 

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 🙂

 

Create a free website or blog at WordPress.com.