I'm working through the Java Ranch Cattle Drive online tutorials and got up to the Servlets projects. I wanted to install and run Apache instead of Orion, because I wanted to learn a more mainstream HTTP server.
I got Apache up and running on my machine (this is a Windows XP/Cygwin environment, so I'm using the Apache package that comes with the latest version of cygwin, currently httpd version 1.3.33)
I'm to the point of directing a browser to http://localhost and the server is correctly fetching the welcome page (index.html) at C:\cygwin\var\www\htdocs.
I've installed Java EE and was able to compile the following Servlet:
import java.io.* ;
import javax.servlet.http.* ;
public class BeeServlet extends HttpServlet
{
public void doGet( HttpServletRequest request , HttpServletResponse response )
{
response.setContentType("text/html");
try
{
PrintWriter out = response.getWriter();
out.println( "a-buzz-buzz ..." );
out.close();
}
catch( Exception e )
{
System.out.println( "cannot get writer: " + e );
}
}
}
This compiles into a .class file without errors. My question is, where do I install this file in the server?
The file is called BeeServlet.class and the tutorial says to direct a browser to http://localhost/servlet/BeeServlet after installing the BeeServlet.class in the appropriate directory in the web server.
(EDIT: I've successfully installed Tomcat and have the basic welcome page showing, as explained in the steps below. I'm still not sure where to put the .class file though or how to access it):
Here's are the steps of installing Tomcat and running it through Cygwin:
Go to http://tomcat.apache.org/ and download the latest version of Tomcat (for the above system configuration, select the 32-bit/64-bit Windows Service Installer method, which will create a 9 MB installation at C:\Program Files\Apache Software Foundation\Tomcat 7.0).
Add this path to the Windows system environment variable 'Path'
Start a Cygwin bash shell
type 'tomcat7' (with Path set, it will find this .exe in the above path). This will start the tomcat server.
Start a browser and direct it to http://localhost:8080. This will bring up the Tomcat welcome screen (which is really Tomcat reading the file: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\index.jsp).
Create new directories under C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps named examples\WEB-INF\classes.
Add a @WebServlet annotation to the source code file (this would be located after any imports): @WebServlet(urlPatterns={"/servlet/BeeServlet"}). Compile the BeeServlet.java file and place the .class file in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF\classes\BeeServlet.class
Direct your browser to http://localhost:8080/examples/servlet/BeeServlet