| |||||||||||
| |||||||||||
Servlet source + web.xml + CLASSPATH all in one example
Tomcat - Configuring Web Applications example from a Well House Consultants training course
More on Tomcat - Configuring Web Applications [link] Source code: Coffeeweb.java Module: A653
/* ------------------------ Coffeeweb.Java ------------------- */
/* */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; // You can have your compiler find these classes via ... // export CLASSPATH=/usr/local/tomcat/common/lib/servlet-api.jar public class Coffeeweb extends HttpServlet{ /* A Coffeeweb is a standard servlet with the following methods added / replaced ... */ public static void main (String [] gerald) { /* This function is not used when we run as a servlet, but can be useful for testing the other stuff in the class in a standalone mode */ System.out.println("Greetings World"); int wide = 4; int deep = 3; int laptops = workitout(wide,deep); System.out.print("The desk should take "); System.out.print(laptops); System.out.println(" little computers"); } private static int workitout(int w, int d) { // Represents the complicated "business logic" // If we can fit a lot of computers we had // better leave space for a cup of coffee for // the guy who is building them all! int spaces = w * d; if (spaces > 10) spaces = spaces - 1; return spaces; } public void doGet (HttpServletRequest inp, HttpServletResponse outp) throws ServletException, IOException { // Handles any GET requests. The look and feel // hard coded into the Java is pretty "yuk" but // it's fine for a first demo outp.setContentType("text/html"); PrintWriter out = outp.getWriter(); out.println("<head><title>Laptops on desk</title></head>"); out.println("<body><h1>Laptop squash</h1>"); // Run the business logic! int numtops = workitout(3,5); out.print("There is room for "); out.print(numtops); out.print(" systems"); out.println("</body>"); } } /* ----------- Code to run this from web.xml (Note - all commented out as far as the Java compiler is concerned! <web-app> <servlet> <servlet-name>George</servlet-name> <servlet-class>Coffeeweb</servlet-class> </servlet> <servlet-mapping> <servlet-name>George</servlet-name> <url-pattern>/deskspace</url-pattern> </servlet-mapping> </web-app> */ Learn about this subject
This module and example are covered on the following public courses:
* Deploying Apache and Tomcat * Deploying Java Applications on Linux / Unix Also available on on site courses for larger groups Books covering this topic
Yes. We have over 700 books in our library. Books
covering Lamp deployment are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "Tomcat - Configuring Web Applications" training module. You'll find a description of the topic and some
other closely related examples on the "Tomcat - Configuring Web Applications" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Web site author
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php4 • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |