[Java.web] Tomcat Common Configuration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.