1. Web. xml file at the bottom (X:\apache-tomcat-7.0.77\conf\ directory)
<welcome-file-list> <Welcome-file>Index.html</Welcome-file> <Welcome-file>Index.htm</Welcome-file> <Welcome-file>index.jsp</Welcome-file></welcome-file-list>
These are the same as the default documents in IIS.
Getting Started with Servlets (from Smart Podcast) 1. Create a new DAY04 Web project in Tomcat, and then create a new web-inf/classes directory in your Web project. 2. Create a new Firstservlet.java file in the classes directory with the contents:
package Cn.itcast; import java.io.*; import javax.servlet.*; public class Firstservlet extends genericservlet{ Span style= "COLOR: #0000ff" >public void Service (ServletRequest req, servletresponse res) throws Servletexception, java.io.ioexception{outputstream out =
Res.getoutputstream (); Out.write ( "Hello servlet!!!"
.getbytes ()); }}
3. Using commands
CD X:\apache-tomcat-7.0.77\webapps\day04\WEB-INF\classes
Set classpath=%classpath%;D: \demo\java\apache-tomcat-7.0.77\lib\servlet-api.jar
Javac-d. Firstservlet.java To reference the external class and compile this Java
After the compilation is successful, a new CN directory is created under the Day04\web-inf\classes directory.
4. Create a new Web. xml file in the Web-inf directory and configure the servlet's external access path, as follows:
<?XML version= "1.0" encoding= "Iso-8859-1"?><Web-appxmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version= "3.0"> <servlet> <Servlet-name>Firstservlet</Servlet-name> <Servlet-class>Cn.itcast.FirstServlet</Servlet-class> </servlet> <servlet-mapping> <Servlet-name>Firstservlet</Servlet-name> <Url-pattern>/firstservlet</Url-pattern> </servlet-mapping></Web-app>
5. Restart the Tomcat service and use site access.
[Java.web] Tomcat Common Configuration