instructions
- How to create a Maven project: Manually
- Benefits: Refer to IntelliJ IDEA 14 to create A Maven project ii (this article describes the benefits of creating a Maven project this way) and Idea14 to create a Web project using Maven (this article describes the disadvantages of creating Maven using templates).
Create a new Maven project
- A new project
- Do not select any Maven templates
- Create GroupId, ArifactId
- Give it a project name. Note: Idea_Project is the working section for this project, and mavenDemo_idea15 is the subdirectory for this project.
- Once the project is built, open it and click auto-import
- The following is the structure of this project
Project deployment
- Click on the
Project: no need to set (of course you can click Project Complier Output to customize the compilation directory)
Modules:You can see that there are no adaptation service components in this item (since Maven was created manually, no Maven templates were selected) — so we need to add them.
- Select Web (add a Web service component to this project, and it is a Web project)
- Now set up the resource directory for the Web. Double-click Web Resource Directory
- Select the SCR /main directory
- Add webApp at the end. OK, click OK, and the Web’s resources directory is set up.
- Now set the directory for the Web’s description file
- The Settings are in the WebApp directory
Facts: represents the adaptation service components of the current project. You can see that this project is already a Web project.
Aftifacts: This Aftifacts describes the information published by the current project. Now add, selecting from Modeles.
A: Now Artifacts are available B:The Output root directory describes the compile directory and adaptation service for the current project.
The structure of the current project after confirmation:
- Add lib packages if necessary
Deployment server
- Adding a Server
- The deployment of
Note: Arifact is not found here for many children’s shoes, please refer to the configuration of Modules in the Deployment project. If there are no Web service components configured for the project, there is no Artifact. (The current project is not even a Web project, where will Artifact come from and what will be deployed?)
- Note the following options:
Writing code tests
- Create a Java class. You can see the problem with inheriting HttpServlet – this is because Tomcat dependencies are not added to Module
- Add Tomcat dependencies to Modules
Is added
- Now just press the shortcut key
- The code editor
Java
package com.wql; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * Created by Lenovo on 2016/2/25. */ @WebServlet("/myController") public class Controller extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // System.err.println("---"); // Req.setCharacterEncoding ("UTF-8"); String name=req.getParameter("name"); req.setAttribute("name",name); System.out.println(name); req.getRequestDispatcher("index.jsp").forward(req, resp); }}Copy the code
Html
<%-- Created by IntelliJ IDEA. User: Lenovo Date: 2016/2/25 Time: 0:26 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html; charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <form action="myController" Method ="post"> <input name="name"> return:${name} <input value=" submit" </form> </body> </ HTML >Copy the code
Xml
<? The XML version = "1.0" encoding = "utf-8"? > <web-app xmlns="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" > <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>Copy the code
- Remember to set the default startup browser
- Start the project
- Thanks to the original author: blog.csdn.net/zhw0596/art…