使用注解配置servlet6

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的描述信息,等价于标签.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章