- Servlets are simply
.class
files, i.e., compiled.java
files. - Servlet files are stored in the
subdirectory of the main web application directory. In this case theWEB-INF/classes
.class
files for theexamples
web app is stored in .%TOMCAT_HOME%/webapps/examples/WEB-INF/classes
- So when the user requests
http://localhost:8080/examples/servlet/HelloWorldExample
Tomcat runs%TOMCAT_HOME%/webapps/examples/WEB-INF/classes/HelloWorldExample.class
- Create a folder inside webppas of Tomcat server (star, for example)
- "\WEB-INF\classes" is the folder to keep Servlet class files
- 'web.xml' is saved in the '/WEB-INF' folder
- Compile command
The url to access the servlet , after starting Tomcat server
http://localhost:8080/star/TestServlet
------------------------------------------------
1- must run Tomcat server then try http://localhost:8080 to verify it works
2- There is a specific structure for the files
3-assign your servlet class to a package, for example at the beginning of the Java file
package org.oats;
4- Need to tell were the servlets resides (the path classes) using web.xml
which is saved in
Finally, again in the web.xml file, add:
That says "When you see the URL /Ontology, call the Servlet name "Ontology",
which is mapped to the 'org.oats.OntologyServlet' class".
5- the two main methods to implement in servlets are doGet and doPost
No comments:
Post a Comment