preface
Installing software and setting up a development environment are the biggest headache every time you change computers. That’s one reason (mostly poverty) for not wanting to change computers. I don’t want to change my computer unless it’s broken and I can’t turn it on or click the card. It takes a long time to change computers.
While changing the computer this time, I will arrange the installation, use and configuration of IDEA.
The official website provides detailed use of the document, good English can be directly used
www.jetbrains.com/help/idea/g…
IntelliJ IDEA introduction
IDEA, full name IntelliJ IDEA, is the Integrated development environment of Java language. IDEA is recognized as one of the best Java development tools in the industry. Once used, it will become addictive. Especially in intelligent code assistant, code autoprompt, refactoring, J2EE
Support, Ant, JUnit, CVS integration, code review, innovative GUI design, and more are supernormal.
IDEA explains itself this way on its official website
Excel at enterprise, mobile and web development with Java, Scala and Groovy, with all the latest modern technologies and frameworks available out of the box. IntelliJ IDEA is mainly used to support the development tools of Java, Scala, Groovy and other languages. At the same time, it has the technology and framework to support the current mainstream. It is good at the development of enterprise applications, mobile applications and Web applications
Advantages of IntelliJ IDEA over Eclipse
- Strong integration ability. For example: Git, Maven, Spring, etc
- Prompt function is fast and convenient
- The range of prompt functions is wide
- Handy shortcuts and code templates
- Accurate search
IntelliJ IDEA download and install
- Download address
www.jetbrains.com/idea/downlo…
DEA comes in two editions: Ultimate and Community. Flagship version: charge (limited to 30 days free trial), comprehensive functions, rich plug-ins, but charge, according to the annual charge; Community edition: free trial, relatively not very rich features, but does not affect the development of use.
- Software and hardware Requirements (Official requirements)
Take the latest version as an example (the latest version is idea-2021.3.2)
- Operating system: 64-bit Versions of Microsoft Windows 10, 8
- Memory: 2 GB RAM minimum, 8 GB RAM recommended
- Hard disk: 2.5 GB hard disk space, SSD recommended
- 1024×768 Minimum Screen Resolution
- JRE 1.8 is bundled with the IntelliJ IDEA distribution. You do not need to install Java
on your computer to run IntelliJ IDEA.
- JDK A standalone JDK is required for Java development
Personal recommended configuration: memory 8G or above, CPU i5 or above is best, it is best to install a solid state disk (SSD), install IDEA on the SSD, so that the flow will be much faster
- The installation process
Double-click the downloaded EXE file for brainless installation
- The activation
Taobao, you know.
Directory Structure
- Installation Directory
Bin: container, execution file, and startup parameters
Idea64.exe. vmOptions is a more important configuration file, here to my personal computer as an example (Win10 64-bit 16G memory)
-Xms512m # Set the initial amount of memory. Increasing this value can improve the startup speed of Java programs
-Xmx1500m # Set the maximum memory count and increase this value to reduce the frequency of Garage memory collection and improve program performance
-XX:ReservedCodeCacheSize=512m Keep the amount of memory that code takes up
-XX:+IgnoreUnrecognizedVMOptions
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
-XX:CICompilerCount=2
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-ea
-Dsun.io.useCanonCaches=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-Djdk.attach.allowAttachSelf=true
-Djdk.module.illegalAccess.silent=true
-Dkotlinx.coroutines.debug=off
Copy the code
- Help: Shortcut key documents and other help documents
- JBR: One of the hardware and software requirements we talked about before installing Intellij Idea is that if you just want to run Java, you don’t need to install JRE because Intellij Idea is already bundled. In the JBR directory, you can see that it already provides the Java runtime environment, of course, if you want to develop Java programs, you will need to install the JDK independently
- Lib: idea dependent library
- License: license of each plug-in
- Plugins: plugins
- Setting a Directory
Path C:\Users\ Users. IntelliJIdea2019.3
This is the directory where the various configurations of IDEA are saved. The Settings directory has a feature that you delete the whole
After 2 directories, restarting IntelliJ IDEA will automatically generate a new default configuration for you, so many times if you change IntelliJ IDEA configuration bad, delete the directory and everything will be restored to the default
(1) the config directory
This directory is the most important directory of IDEA. The directory mainly records: IDE main configuration functions, custom code templates, custom file templates, custom shortcuts, Project tasks records and other personalized Settings
(2) the system directory
The system directory is the IntelliJ IDEA system file directory, which is a bridge directory between IntelliJ IDEA and development projects. It mainly contains: cache, index, container file output and so on
Create a Java project to implement Hell World
- Create a project
- Create New Project: Create a New Project
- Import Project: Imports an existing Project
- Open: Opens an existing project. For example, you can open the Eclipse project.
- Check out from Version Control: Check out Github from the project address on the server
Projects above or on other Git-hosted servers
Select Create New Project
IntelliJ IDEA has no eclipse-like concept of Workspaces, and the largest unit is Project. Project can be understood here as a Workspace in Eclipse.
- Select JDK version, framework
- Select a template
- Set the project path and project name
- Program interface
- The SRC directory under the project is similar to the SRC directory under Eclipse for storing code
- The. Idea and project01.imL files under the project are specific to the IDEA project. Similar to Eclipse work
.settings,.classpath,.project, etc
- Create package and class
Create a package in the SRC directory
Create a new class under the package you just built
Declare the main method in the HelloWorld class, and the console prints HelloWorld! This completes successfully
Introduction to modules
In Eclipse we have the concept of Workspace and Project, in IDEA
In Eclipse, workspace is equivalent to Project in IDEA. In Eclipse, Project is equivalent to Module in IDEA
Eclipse can manage n projects in the same window, which IntelliJ IDEA cannot.
The solution provided by IntelliJ IDEA is to open multiple project instances, that is, multiple project Windows. That is, a Project opens a Window
In IntelliJ IDEA, Project is the top level, followed by Module. A ProjectIntelliJ IDEA installation, configuration, and use can have multiple modules. Today’s mainstream large projects are distributed and structured like this multi-module structure
The following figure shows the screenshot of the project module. According to the model name, they are under the same project and have an inseparable business relationship with each other
Small projects are less complex than multiple Module projects, and IntelliJ IDEA creates projects with a single Module structure by default.
- A project in IntelliJ IDEA is based on modules, so let’s look at creating and deleting modules
① How to create a Module?
After that, we can write code in Module SRC, and Project SRC is useless. I can delete it.
② How to delete a Module?
- remove Module
- delete Module
Until the second step is complete, the Module is completely removed from disk
Viewing project Configuration
IDEA Common Configuration
File –>Settings Goes to the Settings screen
- Appearance & Behavior
① Set the theme
The default themes are as follows. You can set them based on your preference
② Set the font and size of the form and menu
- Editor – General
① Set the mouse wheel to change the font size
② Set the mouse hover prompt
③ Set automatic packet guide
- Add unambiguous imports on the fly: Automatically import ambiguous structures
- Optimize imports on the fly: Automatically Optimize imported packages for us
④ Set the display line number and method separator
- As shown in the red circle above, check Show Line numbers to display the number of lines. Check the suggestion box to locate the code
- Select Show Method separators, as shown in the red circle above. Suggestion check box, a single method code is more, good to distinguish a method where to end
⑤ Ignore case hints
- IntelliJ IDEA’s code hints and supplements are case sensitive by default. We type stringb without prompting
- As shown above, the code prompts are case insensitive after we remove the check box before the Match case. Type stringb and you’ll be prompted
⑥ Disable the single line display of tabs
IntelliJ IDEA by default displays all open file names on a single line when opening many files. If you need to display the file in more than one line, you can use the Settings shown above
- Editor – the Font
① Set the default font, font size, and line spacing
- Editor – Color Scheme
① Change the font color of the comments in the code
- Doc Comment -text: Changes the font color of document comments
- Block comment: Changes the font color of multi-line comments
- Line comment: Changes the font color of the Line comment
- Editor – File and Code Templates
① Modify the document comment information of the class header
/ * *@author xiezhr
@create ${YEAR}-${MONTH}-${DAY} ${TIME}
*/
Copy the code
- Editor – File Encodings
① Set the encoding format of project files
- Build,Execution,Deployment
① Set automatic compilation
- Intellij Idea is not automatically compiled by default, and Eclipse is automatically compiled by default. If you’re from Eclipse, you need to set it up here.
- Sets the code to be displayed horizontally or vertically
Shortcut Settings
- Intellij Idea supports setting shortcut keys as Eclipse shortcut keys.
- Import shortcut key Settings
- Common shortcut keys (those marked ⭐ are common)
1) editing class
shortcuts | Shortcut Keys |
---|---|
Ctrl + Space | Completion code, because often with the operating system input method switching conflict, so rarely used. Generally, the input auto-completion mechanism is directly enabled in idea |
Ctrl + Shift + Space | Only the information most relevant to the keyword you entered is displayed in the list of options. ⭐ |
Ctrl + Shift + Enter | After code completion, the semicolon terminator is automatically added to the end of the code |
Ctrl + P | In a method, when the key is called, the method’s call parameter list information is displayed |
Ctrl + Q | Shows the API documentation for a class or method |
Ctrl + mouse | Jump into the source code of a class or method and look at ⭐ |
Alt + Insert | Automatically generates Getters, Setters, Constructors, hashCode/equals, toString, etc. for a class ⭐ |
Ctrl + O | Displays a list of all overridden or implemented methods in the class |
Ctrl + Alt + T | Automatically generate code with surround properties, such as: if.. else,try.. Catch, for, synchronized, etc., should be used before selecting the code block to surround ⭐ |
Ctrl + / | Add or remove comments for a single line of code. There are two cases: if the cursor is hovering on a line, continuous use of the shortcut will comment out the next line of code; If a line of code is selected (or part of a line is selected), using the shortcut continuously toggles between adding and removing comments on that line ⭐ |
Ctrl + Shift + / | Add or remove comments to code blocks. It differs from Ctrl + / in that it only adds the comment symbol ⭐ to the beginning and end of the code block |
Ctrl + W | Select the current cursor in the code block, triggered for several times, the code block will gradually become larger ⭐ |
Ctrl + Shift + W | Is the reverse operation of Ctrl + W, triggered many times, the code block will become smaller step by step, at least into the cursor |
Alt + Q | Displays the parent node information that contains the code where the cursor is currently located, such as when called in a Java method, displaying method signature information |
Alt + Enter | Displays the current current cursor location code, can change the extension operation |
Ctrl + Alt + L | Formatting code ⭐ |
Ctrl + Alt + O | Remove packages that are not actually used, which is especially useful in Java classes ⭐ |
Ctrl + Alt + I | Automatically indents the selected code segment according to the indent setting |
Tab / Shift + Tab | Indent or unindent the selected snippet ⭐ |
Ctrl + X or Shift Delete | Clip the current code ⭐ |
Ctrl + C or Ctrl + Insert | Copy the current code ⭐ |
Ctrl + V or Shift + Insert | Paste previously cut or copied code ⭐ |
Ctrl + Shift + V | From the previously cut or copied code history, select what you want to paste now ⭐ |
Ctrl + D | Copy the currently selected code ⭐ |
Ctrl + Y | Delete the line of code where the current cursor is located ⭐ |
Ctrl + Shift + J | Continues the next line of code to the current line of code |
Ctrl + Enter | Insert a blank line between the current line of code and the next line of code with the same cursor ⭐ |
Shift + Enter | Insert a blank line between the current line and the next line, with the cursor now on the new blank line ⭐ |
Ctrl + Shift + U | The selected content is case-transformed ⭐ |
Ctrl + Shift + ]/[ | Select from the current cursor position to the beginning or end of the code section |
Ctrl + Delete | Deletes everything from the current cursor position to the end of the word |
Ctrl + NumPad(+/-) | Expand or contract the code snippet ⭐ |
Ctrl + Shift + NumPad(+) | Expand all code snippets |
Ctrl + Shift + NumPad(-) | Shrink all code snippets |
Ctrl + F4 | Close the current TAB |
Shift + F6 | Change the name ⭐ |
② Find the replacement
shortcuts | Shortcut Keys |
---|---|
Ctrl + F | Searches within the current TAB page and supports the regular expression ⭐ |
F3 | If multiple lookup results are found, each call will jump to the next result, which is very convenient |
Shift + F3 | Is the reverse of F3, which jumps to the previous result each time it is called |
Ctrl + R | Replace in the current TAB ⭐ |
Ctrl + Shift + F | Go to ⭐ |
Ctrl + Shift + R | Replace ⭐ with the path |
graphic | instructions |
---|---|
Up arrow | The shortcut key [Shift + F3] jumps to the previous result every time it is called |
Down arrow | Is the shortcut key [F3], each call will jump to the next result |
The plus sign | Adds the current highlight item to the selected list |
The minus sign | Removes the current highlight item from the selected list |
Check the symbol | Select all the results at the same time, which is good for batch operations |
The upward arrow within the text | The query result list panel is displayed |
Two boxes with a down arrow | More options |
Match Case | Case sensitive |
Regex | Regular expression |
Words | Match the words |
x matches | X is the number of records found |
④ Check the usage
shortcuts | Shortcut Keys |
---|---|
Alt + F7 | Usage in the current project, a usage panel opens |
Ctrl + F7 | Use in the current file, the contents of the search will be highlighted low |
Ctrl + Shift + F7 | Usage in the current file, the contents of the search are highlighted |
Ctrl + Alt + F7 | Open the usage list ⭐ |
④ Compile and run
shortcuts | Shortcut Keys |
---|---|
Ctrl + F9 | Compile the project (if it has been compiled before, only the modified classes or dependent packages ⭐ are compiled |
Ctrl + Shift + F9 | Compile the selected range (if in a class, only the current class is compiled) |
Alt + Shift + F10 | A list of configured runs opens, allowing you to select one before running it |
Alt + Shift + F9 | A list of configured runs opens, allowing you to select one to run in debug mode |
Shift + F10 | Run the run instance of the current configuration immediately, which is especially useful in unit testing ⭐ |
Shift + F9 | Run the currently configured run instance ⭐ immediately in compile mode |
Ctrl + Shift + F10 | Run the related program according to the file type bound by the editor. For example, an HTML page, when called, will directly open a browser |
(5) the debugging
shortcuts | Shortcut Keys |
---|---|
F8 | Skip to the next line of the current code ⭐ |
F7 | Jump to the internal code of the called method ⭐ |
Shift + F7 | A panel opens that lets you select the specific class method to jump into, which is especially useful in complex nested code |
Shift + F8 | Jump out of the current class and go up to ⭐ |
Alt + F9 | Let the code run to the current cursor location, very nice function ⭐ |
Alt + F8 | Open an expression panel and perform further calculations |
F9 | End the current round of debugging for the breakpoint (because it is possible that the code will be called multiple times, so it only ends once); If there is a next breakpoint it jumps to the next breakpoint ⭐ |
Ctrl + F8 | Add or remove breakpoints at the current cursor |
Ctrl + Shift + F8 | Open the current breakpoint panel, can be conditional filtering oh |
6. Navigation
shortcuts | Shortcut Keys |
---|---|
Ctrl + N | Open the class query box ⭐ |
Ctrl + Shift + N | Open the file query box ⭐ |
Ctrl + Alt + Shift + N | Open the text query box |
Alt + right arrow/left arrow | Skip to the next/previous editor TAB |
F12 | If you are in the edit window, it will jump to the toolbar you previously operated |
ESC | From the toolbar, and then jump back to the original edit window, generally used with F12 |
Shift + ESC | Hide the last active tool window |
Ctrl + Shift + F4 | Also close some toolbar Windows that are active |
Ctrl + G | Jump to a line of code ⭐ |
Ctrl + E | Open a history list of files you have manipulated |
Ctrl + Alt + right arrow/left arrow | Jump back and forth between previously viewed lines of code |
Ctrl + Shift + Backspace | Jump to the most recent edit location (if you’ve edited the code before) |
Alt + F1 | Opens a list of types, which, when selected, navigates to a type-specific panel for the current file or content |
Ctrl + B or Ctrl + left mouse button | If it is a class, it jumps to the class definition or interface where the cursor is. If it is a variable, a list of references to the variable is opened ⭐ |
Ctrl + Alt + B | Jump to the implementation class instead of the interface ⭐ |
Ctrl + Shift + I | Open a panel that contains the class code |
Ctrl + Shift + B | The class code corresponding to the type of the open variable is only useful for the variable |
Ctrl + U | Opening a superclass method of a method or a superclass of a class only works on a method or class that has a superclass |
Alt + up/down arrow | In a class, jump to the signature of the previous/next method |
Ctrl + ]/[ | Move the cursor to the closing or opening curly brace of the class definition |
Ctrl + F12 | Open the structure list of the class ⭐ |
Ctrl + H | Open the list of class inheritance relationships |
Ctrl + Shift + H | Opens a list of inheritance relationships for a class method |
Ctrl + Alt + H | Open a list of methods for all classes that call one of the class methods at the current cursor ⭐ |
F2/Shift + F2 | Jump back and forth between lines of code that failed to compile |
F4 | Open the source code for the method or class where the current cursor is located |
Alt + Home | Activate the navigation bar for the package path |
F11 | Bookmark the line of code at which the cursor is located or remove ⭐ from the bookmark |
Ctrl + F11 | Add or remove the line of code where the cursor is located from a shortcut bookmark. |
Shift + F11 | Open the bookmark list ⭐ |
Ctrl + N (Open the class query box)
Type the keyword of the class name, it will automatically appear the related class, very powerful
Alt + F1 (opens a list of types)
Template Settings
Templates include Live Templates and Postfix Completion
The difference: Live Templates can be customized, but Postfix Completion cannot
- Live Templates Live Code Templates
Configure some common code abbreviations, in the input abbreviations can appear your predefined fixed pattern of the code, making the development efficiency greatly improved.
System.out.println(); system.out.println ();
- An existing common template
For example, (1) PSVM
PSVM generates the main method
(2) the sout
Sout generates system.out.println ()
Iter: can generate enhanced for loop ITAR: can generate ordinary FOR loop
List list = new ArrayList(); For (String s:list){}
If (XXX = null) inn: if(XXX! = null) xxx.nn or XXX.null
⑥ PRSF PRSF generates private static final PSF generates public static final PSFI generates public static final int PSFS generates public static final String
- If you are not used to an existing template, modify it
- If you are not used to existing templates, you can also define your own template
① Define a template group
② Define a template in the template group defined in the previous step
③ Select the application scope
Associated database
- Associated database
The biggest feature of IntelliJ IDEA Database is that for Java Web projects, ORM frameworks commonly used, such as Hibernate and Mybatis, have good support. For example, after configuring the Database, IntelliJ IDEA automatically identifies the relationship between domain objects and data tables, and can generate domain objects directly from Database data tables, etc
- Common operations
- Icon 1: Synchronize the current database connection. This is the most important operation. After configuring the connection or using other tools to operate the database, you need to synchronize data in a timely manner.
- Icon 2: Configure the current connection.
- Icon 3: Disconnect the current connection.
- Icon 4: Displays data for the corresponding database object
- Icon 5: Edit or modify the current database object
Version control
Versioning is essential for both individual and team development, and IntelliJ IDEA also integrates versioning tools.
Note: Although IntelliJ IDEA provides plug-in support for these version control tools by default, we need to install our own version control client
- Git is a common version control tool and the most advanced distributed version control system in the world. How to configure and use Git
① Download and install the Git client
Download from git-scm.com/downloads
All brainless next step can be installed
After the default installation is complete, right-click and the icon shown in the following figure shows that the installation is successful
After the installation is complete, you need to take one final step to set it up by typing:
The --global parameter of the git config command indicates that all git repositories on your machine will use this configuration
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Copy the code
Because Git is a distributed version control system, every machine must identify itself: your name and Email address
(2) associated with git. Exe
③ Associate your GitHub account and test the connection
④ Create a new repository for your GitHub account as a test
⑤ checkout the project from your current github account
Get the project path on GitHub and fill it with the project path
Follow these steps to clone your project locally on GitHub. Isn’t that easy
⑥ Git common operations
Clone: copies the remote repository. Commit: commits the remote repository. Push: commits the remote repositoryCopy the code
Git commands are only the most commonly used commands. If you want to learn more about Git, check them out
Git tutorial by Liao Xuefeng
Note: Even if we don’t use any version control tools, IntelliJ IDEA provides us with the ability to view historical versions
Breakpoint debugging
- Debug Mode Setting
Set the Debug connection mode, which is Socket by default. Shared Memory is a Property specific to Windows. It is recommended to use this property in Windows operating systems
- Common breakpoint debugging instructions
icon | According to | instructions |
---|---|---|
step over | To go to the next step, do not enter the current method body if the current line breakpoint is a method | |
step into | To go to the next step, enter the current method body if the current row breakpoint is a method | |
force step into | To go to the next step, enter the current method body if the current row breakpoint is a method | |
step out | Jump out of the | |
resume program | Resumes the program running, but stops at the next breakpoint if the code below that breakpoint still has a breakpoint | |
stop | stop | |
view breakpoints | View all breakpoints |
- Conditional breakpoints
In a real project, we would encounter a scenario like this. We have located the problem (bug) in this loop, but we are not sure how many times the loop will report an error.
When the number of loops is small, 3 or 5, we can debug one at a time. But what about 100 times, or even 1,000 times? And that’s where conditional breakpoints come in.
Adding conditional judgments to the loop can greatly improve our efficiency
Click in front of the statement that needs to set breakpoints. When a red breakpoint appears, right-click to add conditions as shown in the figure below.
Debug program that stops when I =10
Configure maven
- Java Project Composition
Before introducing Maven, let’s look at what the next Java project needs.
- If we need log4j, we need to put the log4j jar package in the classpath, and if we need Fastjson, we need to put the FastJSON JAR package in the classpath. This is dependency package management
- We need to determine the directory structure of the project. For example, the SRC directory holds Java source code, the Resources directory holds configuration files, and the bin directory holds compiled.class files
- We also need to configure the environment, such as the version of the JDK, and compile the packaged process
- The code needs to be compiled so that the project can be compiled, tested, and deployed on a separate server
- Maven profile
These tasks are not difficult, but they are trivial and time-consuming. If each project had its own set of configurations, it would be time-consuming and laborious. What we need is a standardized Java project management and build tool
Maven is a management and build tool specifically built for Java projects. Maven has the following capabilities
- Provides a standardized project structure
- Provides a standardized build process (compile, test, package, publish…)
- Provides a dependency management mechanism
- Maven Project Structure
- Maven Build Process
- IntelliJ IDEA configures Maven
- Creating a New Maven Project
① New project
② Select Maven project
③ Set project parameters
4 configure local Maven Settings
⑤ Initialize the project
⑥ Project construction is completed
- Add third-party JAR packages
Mysql is a common database in our daily development. Here we take the mysql driver package import as an example
Mysql driver package is not included in app.java
② Modify the POM. XML file and add the following content
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.20</version>
</dependency>
Copy the code
Note: We don’t need to memorize the contents of the Dependency TAB, just go to mvnrepository.com/ and copy
③ Wait until the driver download is complete
(4) Run the command again
Create a Web project and configure Tomcat
- Create a New Maven Web project
① Create a project
② Select Maven WebApp format
③ Fill in project parameters
4 set local Maven parameters
⑤ Configure the Java source directory
Maven Web projects don’t have Java source directories by default, so you need to create them manually, Right-click the main Directory-> New->Directory-> Enter Java -> right-click Java ->Mark Directory as-> Sources Root
This creates a directory for your Java source files
6 new servlet
package com.xiezhr;
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;
import java.util.Date;
@WebServlet(name = "HelloServlet")
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println("Hello Servlet! Hello xiezhr!
");
response.getWriter().println(newDate().toLocaleString()); }}Copy the code
All landowners to modify web. XML
<! DOCTYPEweb-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.xiezhr.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
Copy the code
Add servlet package dependencies to POM.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
Copy the code
- Configure tomcat
1 Open the Tomcat configuration and select the Tomcat path
② Deployment Settings
③ Operation project
④ Test success