使用注解配置servlet6

来源:互联网 发布:消费观念 知乎 编辑:程序博客网 时间:2024/05/29 13:00

metadata-complete属性指定是否启用注解和web模块:
无指定或者false启用;反之。。。
只有Servlet类在web-inf/classes目录中或者打包到位于web-inf/lib的jar文件才起作用

<?xml version="1.0" encoding="UTF-8"?><web-app metadata-complete="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">  <display-name>project5</display-name>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list></web-app>

metadata-complete=”false”

@WebServlet(name = "servlet1", initParams = { @WebInitParam(name = "name1", value = "value1") }, urlPatterns = "/servlet1",loadOnStartup=1,asyncSupported=true)public class Servlet1 extends HttpServlet {。。。。。。。。。}

value与urlpattern不能同时给,否则启动就要报错
urlpattern不能与web.xml中配置的重复

属性名 类型 属性描述
name String 指定servlet的name属性,等价于.如果没有显示指定,则该servlet的取值即为类的全限定名.
value String[] 等价于urlPatterns,二者不能共存.
urlPatterns String[] 指定一组servlet的url的匹配模式,等价于标签.
loadOnStartup int 指定servlet的加载顺序,等价于标签.
initParams WebInitParam[] 指定一组初始化参数,等价于标签.
asyncSupported boolean 申明servlet是否支持异步操作模式,等价于标签.
displayName String servlet的显示名,等价于标签.
description String servlet的描述信息,等价于标签.

原创粉丝点击