1.在mian下新建java包
2.将java包设置为根路径
3.新建包(如图)
4.在controller包下创建java class(名为LoginController),并在类中添加如下字
5.到maven官网上复制httpServlet-api到pom.xml中,网址https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.1.0
6.在类中导入相应包,重写doget和dopost方法
7.配置servlet有两种方式,web.xml中配置servlet属性和在@WebServlet中配置。
方式一:添加@WebServlet("/login")
方式二:在web.xml中配置
8.浏览器运行:
登录成功:
登陆失败:
补充:
若报错:java.lang.IllegalAccessException: Class org.eclipse.jetty.servlet.ServletContextHandler$Context can
请参考:
https://blog.csdn.net/single__s/article/details/105207594
若报错:[ERROR] Failed to execute goal org.mortbay.jetty:jetty-maven-plugin:8.1.16.v20140903:run (default-cl
请参考:
https://blog.csdn.net/single__s/article/details/105206864