Steps to build web project with maven

1. Create a maven project (and add the web skeleton at the same time)

1. Create a new maven project. When creating the project, select: maven-archetype-webapp skeleton, and then select Next

2. Then name the project, then select the save path of the project, and then click Next.

3. Then select the maven version, check the small box on the right, then add the path to the maven configuration file, add the path to the maven local warehouse, and then click Finish.

4. After clicking Finish, it will look like the picture below:

2. Restore file directory

5. Right-click src, then select New Directory, add the four options shown below, and click Enter.

6. The newly created directory will look like the following

7. Right-click the java directory, then add the com.heima.mapper package and com.heima.pojo package to create an html folder in the webapp directory. The resources folder under the java directory is used to store the xml configuration files of project architectures such as mabtis. The finished product is as shown below:

3. Modify the pom.xml file

8. Delete unnecessary plug-in configuration code in the pom.xml configuration file. Only keep the code in the picture below.

4. Solve possible problems

9. Possible problems:

Comparing the above two situations, we found that under normal circumstances, the webapp has a small blue dot on the left side. If there is a problem as shown in the above picture, you can try to use the following methods to correct the error:

https://blog.csdn.net/qq_45780016/article/details/124342388

5. Modify the web.xml file

Prerequisite: If the web.xml file format is the same as the format modified in this step, no modification is required; if the web.xml file format is as shown in the figure below, no modification is required. This style of web.xml file does not support annotations, and problems will occur when subsequent servlets and JSP are used together, so we need to delete and rebuild the web.xml file.

Proceed as follows:

10.1、点击右边的项目结构图标,然后选择modules,然后找到当前项目的Web并点击,然后选择Type下面的内容,点击右边的减号,然后选择OK,然后点击应用(点击应用之后不要点确认),流程如下图所示:

10.2、按照10.1的步骤操作之后,点击右边的加号,选择web.xml,如下图所示:

10.3、执行完10.2的步骤,会出现一个弹窗,注意文件的路径,然后version的值一定要大于等于2.4,不然EL表达式不会被servlet识别,然后点击本窗口的确定,然后点击应用,再点击确认即可,如下图所示:

10.4、查看修改后的web.xml文件,如下图所示就算成功了。

6、为了避免每次建新项目都需要修改web,xml文件,可以直接修改web.xml文件的默认的模板,具体操作步骤可以查看下方链接中最佳解决方案标题下的内容

链接:https://blog.csdn.net/aiains/article/details/129466693?spm=1001.2014.3001.5502

11、导入依赖

Guess you like

Origin blog.csdn.net/aiains/article/details/129171641