使用註解配置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的描述信息,等價於標籤.

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