The Story behind Servlet
Servlet is a piece of code sitting at the server side and waiting for the information from the browsers. It then processes the information and possibly gives feedback to the browsers.
The servlet I’m talking about here is implemented using the Java langauge and runs in Tomcat web server. Long story short, a typical servlet example written in Java is as follows:
Put the above code into your favorite text editor and save as a .java file, e.g. One.java.
Take the servlet-api.jar
file from the lib
directory of the installed tomcat home directory and put it in the same directory as One.java, then run the following command in the command line:
javac -cp servlet-api.jar One.java
After that, you should get a file called One.class in your working directory. Put the One.class in the following created directory in the tomcat home:
$tomcat_home/webapps/one/WEB-INF/classes/
Create and put a web.xml file in the $tomcat_home/webapps/one/WEB-INF/
. The web.xml should look as follows:
Now what you need to do is start tomcat and type the following address in the location area of the browser and enjoy your accomplishment .
http://localhost:8080/hello
All the above is the short story behind the servlet and more infomation can be obtained from the book Professional Java for Web Applications by Nicholas S. Williams.