具体操作:pom.xml中添加
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
- package com.itheima.web;
-
- import javax.servlet.*;
- import javax.servlet.annotation.WebServlet;
- import java.io.IOException;
- @WebServlet("/demo1")
- public class ServletDemo1 implements Servlet {
-
- public void init(ServletConfig servletConfig) throws ServletException {
-
- }
-
- public ServletConfig getServletConfig() {
- return null;
- }
-
- public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
- System.out.println("hello servlet");
- }
-
- public String getServletInfo() {
- return null;
- }
-
- public void destroy() {
-
- }
- }
-
报错了

解决方案:
在pom.xml中加入
<!-- 我是最新的jdk所以写的是9 根据你自己的jdk版本写 1.7/1.8~~~~ --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>9</maven.compiler.source> <maven.compiler.target>9</maven.compiler.target> </properties>
运行run maven
报错
Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"]
8080端口被占用
以管理员身份打开cmd
输入taskkill /f /t /im java.exe
杀死进程
再重新运行maven


返回idea在控制台有输出
