Tomcat Configuration and WEB application development __web

Source: Internet
Author: User
Tags tomcat server
  Tomcat is a server software that is dedicated to Web services.     1. Run: After setting up, you can run the Tomcat server, enter Tomcat's Bin directory, Windows startup tomcat with startup, and the corresponding shutdown Tomcat command for shutdown and shutdown.sh. You can enter the http://localhost:8080/test in the browser after startup. You can test its own JSP and servlet samples.       http://www.it315.org/a.html     Browser sent to the server information: get/a.html http/1.1   The    server will go to the root directory to find a.html files. This root directory is "Tomcat installation directory/webapps/root".     if/on behalf of "C:/ABC"     then go to find c:/abc/a.html file.       virtual directory:     http://www.it315.org/xxx/a.html     If you put the "/xxx" above Mapped to "d:/"     then go and find d:/a.html files.       127.0.0.1: On behalf of local     localhost: typically configured as local, not in essence. Can be changed in windows/system32/drivers/etc/hosts file.     http://www.it315.org:8080 will resolve www.it315.org, first of all www.it315.org in the hosts in the corresponding IP address, can not find to go   find DNS       A site can have more than one virtual directory, each virtual directory is a stand-alone Web application. Each Web application has its own configuration information.       jar-cvf fiLename.war packaged files     JAR-CVF filename.war-c packaged folders in the folder where files       servlet are being web-served The device to invoke.   HTTP request, response, and header information: 1. The request message sent by the client is a text stream and consists of the following: The request line includes a method, a uniform resource identifier, and an HTTP protocol version. Header information               Typical request messages are similar to the following:               
Get Image/bar01.jpg http/1.1 user-agent:mozilla/4.0 (compatible; MSIE 4.0:windows) accept:image/gif,image/jpeg,text/*,*/*
The first line uses the Get method to obtain the Bar01.jpg file and specifies that the version of HTTP protocol 1.1 is in use, followed by the header information, the User-agent header instructs the client to use the browser, the Accept header provides a list of MIME types that the client can accept, and after the header information, the client sends a blank Line that indicates the end of the message request, and the form content is submitted as an entity after a blank line if there are content such as a form. 2. The request message is processed by the server, and the corresponding message is generated, and the response message consists of the following elements: State wardrobe information Entity content (that is, what you want to display in a Web page) the following is an example of a typical response message:
http/1.1 OK server:javawebserver last-modified:tuesday,07-sep-04 1:14:34 GMT content-length:100 Content-type:text/ Plain
The first behavior state line, where the status code 200 indicates that the request was successfully processed, so the description is "OK", and 404 is unable to find the status code that the Web page often encounters, followed by the header information until the blank line. Including the server use of software, file last modified time, length and content of the type of information, blank line is the entity content.        Web applications: Java-based Web applications consist of servlet, Jsp, image, HTML, JavaBean, applets, and so on. An easy way to deploy a Web application is to package all the files associated with the Web application into a. war file, and all Web containers that are compatible with the Servlet specification support the. War file. A Web application has a top-level directory, which generally consists of the following: 1.   Static files: including HTML files and images. 2.  jsp page File 3.  web-inf folder: Note that the directory cannot be referenced. Consists of the following sections:      Classes Directory: Servlet class, JavaBean class, and all other class files.      lib directory: contains all. jar files required by the Web application. such as database connection packs.      Tags directory: contains a custom tag to provide implementation of the tag file      web.xml:Web application of the deployment descriptor file. This file contains metadata information about Web applications, such as the default pages to be displayed, the servlet to be loaded, and so on        set the virtual subdirectory of the Web site: 1.   A/demo virtual subdirectory that maps the C:/webdemo directory on the local computer to a Web site can be configured as follows: Open the Tomcat installation directory/conf/server.xml file and add a row between the Note: When this step executes the jar command if there is no Web.xml file in the Web-inf folder of this directory, Tomcat uses the default Web.xml file content, and if so, the Web.xml file must be written correctly (including syntax and configuration). 3.   can also directly copy C:/webdemo to the Tomcat installation directory/webapps directory, but must have a web-inf directory, If there are web.xml files in the Web-inf directory, this web.xml file must be written correctly (including syntax and configuration).      below is a simple servlet file to write, compile, register, and run the process: 1. First create a new WebRoot directory with the following file structure: WebRoot |-web-inf folder                |-classes Folder               |             |-helloservlet.class files                   |-web.xml File                2. Write a servlet file with the sample code as follows:              //Import some classes to use               import java.io.IOException; ImPort Java.io.PrintWriter;   Import javax.servlet.ServletException; Import Javax.servlet.http.HttpServlet; Import Javax.servlet.http.HttpServletRequest; Import Javax.servlet.http.HttpServletResponse;                             //Inherit HttpServlet public class HelloServlet extends HttpServlet {                         private static final long serialversionuid = 1L;                        //Overriding service methods in the parent class                       @Override                       protected void Service (HttpServletRequest request,                              HttpServletResponse Response) throws Servletexception, IOException {                            // Get an output stream from the HttpServletResponse                             PrintWriter out = Response.getwriter ();                              out.println ("

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.