War package compilation and packaging publishing

Source: Internet
Author: User

Write a basic webapp with the IDE

To learn Java Web technology, in addition to javase basic skills, the basic knowledge and servlet technology. If we only use the IDE, we will block out a lot of problems, many of the details are not clear. The best way is to use the IDE to do a simple war package, unzip the file structure, then manually hit a war package try to comb the compilation process.

The IDE I'm using is IntelliJ, and the step is File | New | Project | Enterprise | WebApplication.

We get a basic WebApp framework:

We write a most basic servlet, only the Doget method is replicated.

import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Firstservlet extends httpservlet
{
    @Override
    protected void doget (httpservletrequest req, httpservletresponse RESP) throws Servletexception, IOException {
        PrintWriter out = Resp.getwriter ();
        out.println ( "This is first servlet! Do get "");
   }
}

 

Configure Web. xml

<?XML version= "1.0"encoding= "UTF-8"?>
<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>firstservlet</Servlet-class>
</servlet>
<servlet-mapping>
<Servlet-name>firstservlet</Servlet-name>
<Url-pattern>/firstservlet</Url-pattern>
</servlet-mapping>



</Web-app>

Once the code is complete, click Build | Make Project, it's already compiled. Then we export the war package, click File | Project Structure | artifacts| WEB Application Archive

Click Build to make a war package.

The war package is available under the Out folder.

Export war packages, run in Tomcat

We download a tomcat, unzip, and under the Bin folder, you can find the name of the open Tomcat.

Put our war pack under Tomcat's WebApp folder and you're ready. Enter Address:

Extract the war package, analyze the structure

The structure diagram of the war package is as follows:

Manually compiling a war package

The demo is as follows: Http://files.cnblogs.com/files/chenjie0949/MyServlet.zip

War package compilation and packaging publishing

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.