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