The School’s Tomcat server works on port 8181.
Currently you could visit school's Tomcat as following URL
http://www.labunix.uqam.ca:8181
You will see the page "Tomcat v3.2.1", and you will find API of servlet
and JSP, as well as some examples.
Let's now follow the below steps to put a "hello" servlet on Tomcat server.
1.
In
one of my classes, I have taught how to put up your own web page in the
school's account. We have created a directory public_html with chmod 755. Check your unix account, if you haven't
done it, do as follows:
% cd
% mkdir public_html
% chmod 755 public_html
2.
Under
public_html, create directory WEB-INF
% cd
% cd public_html
% mkdir WEB-INF
% chmod 711 WEB-INF
Tomcat will automatically search servlet in
this directory.
3.
Under
public_html/WEB-INF, create directory classes
% cd
% cd public_html/WEB-INF
% mkdir classes
% chmod 755 classes
4.
Create
a file web.xml and save it in
public_html/WEB-INF
%chmod 644 web.xml
for hello,
we use the file of web.xml as follows.
<?xml
version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
<web-app>
</web-app> |
5.
Create
a servlet file now. For this hello example let's create hello.java, and save it in the directory
of public_html/WEB-INF/classes
hello.java.
public class hello extends HttpServlet { public void
doGet(HttpServletRequest request, { |
6.
Complie
hello.java using the following command.
javac hello.java
7.
Set
permission for hello.class:
chmod 755 hello.class
Before you do
the following steps, please double check what you have done so far, be sure
that no errors in those files. !
8.
Visit
this URL
http://www.labunix.uqam.ca/~your code here/servlet/hello
9.
You
can go
/var/log/tomcat.log to see any problem when you run your program.