如何重写继承HttpServlet类
1、在 src ->main 中创建一个Directory(标记目录为Source Root)
2、在创建好的目录下建包:cn.edu.mju.projrct2.comtroller
webapp是存放各种图片、视频等jsp资源的根路径,标记为Resources Root(浏览器可以直接访问,如果存放在WEB-INF中是需要间接访问的)
3、在创建好的包下建类:LoginController
4、在 mvnrepository.com网站中搜索 HttpServlet-api ,将javax-servlet-api插件包中的代码复制到pom.xml文件的dependency中运行调试
代码:
<groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope>
5、重写继承 HttpServlet的方法:
右键 Generate -> Override Methods -> doGet和doPost
重写示范代码:
public clsaa LoginController extands HttpServlet{@Overrideprotected void doGet (HttpServletletRequest rep, HttpServletResponse resp) throws ServletException, IOException{System.out.print(\"doGet\");}@Overrideprotected void doGet (HttpServletletRequest rep, HttpServletResponse resp) throws ServletException, IOException{System.out.print(\"doPost\");}}
6、调用Servlet容器(编写登录界面)