|
|
III. Configuration of Apache Tomcat:
Recall that Tomcat is the engine of the servelet. The servlet plays the
role of CGI (Common Gateway Interface), with respect to Perl. That is a
dynamic graphical user interface.
By default, a program running on a browser, like PHP, CGI, Apache, Microsoft
IIS, and Tomcat are set on the 8080 port number.
Without IIS, Apache runs on localhost, Installing Tomcat gives a conflict
regarding localhost machine (127.0.0.1). The solution is to install the mod_jk
module web server connector.
Go to :
http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/
Then:
http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.25/
Download the related connector mod_jk-apache-2.2.4.that is for Apache 2.2,
rename it as mod_jk.so and istall it at the \Apache\modules director like:
C:\Program Files\Apache Software Foundation\Apache2.2\modules
Configure Apache. Open the file:
C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf
Comment: #LoadModule proxy_module modules/mod_proxy.so
Uncomment: LoadModule jk_module modules/mod_jk.so
One should have Apache on localhost:8080 and Tomcat at localhost.
1. Go to:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
examples\WEB-INF\web.xml
and put in, the two tags, in the place like the others, with the
name of your servlet, "Regards"
<servlet>
<servlet-name>Regards</servlet-name>
<servlet-class>Regards</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Regards</servlet-name>
<url-pattern>/servlets/servlet/Regards</url-pattern>
</servlet-mapping>
2. Go to:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\server.xml
and change 8080 to 80 in:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector executor="tomcatThreadPool"
port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
3. Go to:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\jk\
workers.properties
All the lines uncommented appear here:
workers.tomcat_home= C:\Program Files\Apache Software Foundation\
Tomcat 6.0
workers.java_home= C:\Program Files\Java\jre1.6.0_03
ps=\
worker.list=ajp13
# worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
# ----> Low lbfactor means less work done by the worker.
worker.ajp13.lbfactor=1
4. Go to:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
examples\WEB-INF\classes
and put your servlet java programes and thier classes there:
5. write a servlet like:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Regards extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("Regards and all the best");
out.close();
}
}
and go to :
C:\Program Files\Apache Software Foundation\Tomcat 6.0\
webapps\examples\servlets
an put in a file.html to call the sevlet:
The servlet will be located at:
http://localhost/examples/servlets/servlet/Regards
The content is:
Regards and all the best
|