1. Create a project
①, open IDEA
② Project name
After clicking Finish, the project is successfully created, as shown below:
Next, create two folders under WEB-INF in the web: classes and lib (where classes store the compiled class files and lib is used to store jar packages)
③, configure the class byte code file path
We click the icon in the operation bar , or File—> Project Structure (shortcut Ctrl + Alt + Shift + S), and then find Module.
Create a class file, and then set its storage path, or this interface.
After setting, the classes directory will turn orange.
④, configure the jar package storage path (lib folder),
Why do we configure the storage path of the jar package: it is because the jar package is directly copied to the created bin directory, the program will not be loaded into these packages when running, so we need to set it up.
First create a lib directory in WEB-INF, the creation method is the same as creating classes.
Then ok
Then, a JavaWeb project is all configured.
2. Configuration items
The configuration project is to configure the JavaWeb project in the Tomcat server. I wrote an article about the configuration and use of Tomcat before . It is similar to that there, so I copied the pictures there.
Click Add Configuration in IDEA, or open the menu Run-> select Edit Configuration.
After the window pops up, click + , then slide down, and then select Local of Tomcat Server (if there is no Tomcat Server, click items more).
After clicking Local, the following interface will appear:
Note: Different IDEA versions may have different interfaces, but the general operation is the same. (My IDEA2018 model, I don't think it is necessary to pursue the latest version, the one that suits you is the best)
The next step is to deploy and run the project in Tomcat. After we configure Tomcat, an interface will pop up under IDEA.
Right-click Tomcat and select Artifacts, then add the project to it, and right-click Run.
Or in Edit Configurations, select Deployment in the created Tomcat container, click the "+" sign on the right, and then select Artifact.
Then right-click Tomcat to run below, you can view the results in the browser.
3. Run the project
We modify the content of the index.jsp page and start Tomcat.
After running, the page will pop up automatically. If there is no pop up, manually enter localhost: 8080.