09-撩课JavaEE-使用注解创建Servlet
2018-09-27 本文已影响1人
撩课学院

传统创建Servlet存在的问题
每一次都要去实现Servlet接口
都要去做配置
从Servlet3.0开始可以直接使用注解的形式来去使用Servlet
创建Servlet
在创建好的Servlet上面有
会有一个@WebServlet("/myServlet")
这个就是一个注解
就相当于在代码上添加了一个小插件。
贴上这个注解后,就不用再去做配置文件,
会在内部自动帮你去做
括号当中的内容就是url-patten的内容,
要在地址栏当中path后面跟的内容
使用注解时的注意点:
在web.xml当中要有一个配置
metadata-complete
是否扫描类当中定义的注解
值为true和false
当为true的时候不扫描,为false扫描
要使用注解就要把此值设置为false
创建步骤




博文全套 视频讲解 点击以下链接查看
https://study.163.com/course/courseMain.htm?courseId=1005981003&share=2&shareId=1028240359