比較完整的部署描述符(DTD)文件的例子
系統(tǒng)
2142 0
<?
xmlversion="1.0"encoding="ISO-8859-1"
?>
<!
DOCTYPEweb-appPUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN""http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"
>
<
web-app
xmlns
="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2eeweb-app_2_4.xsd"
version
="2.4"
>
<
display-name
>
TestWebapp
</
display-name
>
<!--
站點(diǎn)名稱
-->
<
description
>
<!--
站點(diǎn)描述
-->
Thisisasampledeploymentdescriptorthatshowstheuseofimportantelements.
</
description
>
<
icon
>
<
small-icon
>
/images/small.gif
</
small-icon
>
<!--
小圖標(biāo)的路徑16*16,必須為gifjpg格式
-->
<
large-icon
>
/images/large.gif
</
large-icon
>
<!--
大圖標(biāo)的路徑32*32,必須為gifjpg格式
-->
</
icon
>
<!--
該標(biāo)志表示應(yīng)用程序能夠在多系統(tǒng)之間運(yùn)行,在有多個(gè)servlet下才需要!
-->
<
distributable
/>
<!--
通常context-param指定數(shù)據(jù)庫(kù)驅(qū)動(dòng)、協(xié)議設(shè)置和URL路徑信息。是application級(jí)的變量.只能跟在web-app之后。
取得常量this.getInitParameter("context");
-->
<
context-param
>
<
param-name
>
locale
</
param-name
>
<
param-value
>
US
</
param-value
>
</
context-param
>
<
context-param
>
<
param-name
>
DBName
</
param-name
>
<
param-value
>
Oracle
</
param-value
>
</
context-param
>
<!--
filter和filter-mapping標(biāo)志必須在任何servlet標(biāo)志之前定義。listener也是
-->
<
filter
>
<
filter-name
>
TestFilter
</
filter-name
>
<
description
>
Justfortest
</
description
>
<
filter-class
>
filters.TestFilter
</
filter-class
>
<
init-param
>
<
param-name
>
locale
</
param-name
>
<
param-value
>
US
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
TestFilter
</
filter-name
>
<
url-pattern
>
/*.jsp
</
url-pattern
>
<!--
如果在servlet上使用該過(guò)濾器:<servlet-name>myServlet</servlet-name>
-->
<
dispatcher
>
FORWARD
</
dispatcher
>
<!--
指定請(qǐng)求轉(zhuǎn)送方式,可設(shè)定為request,include,forward,error四種
-->
</
filter-mapping
>
<!--
Definesapplicationeventslisteners
-->
<
listener
>
<
listener-class
>
listeners.MyServletContextListener
</
listener-class
>
</
listener
>
<
listener
>
<
listener-class
>
listeners.MySessionCumContextListener
</
listener-class
>
</
listener
>
<!--
Definesservlets
-->
<
servlet
>
<
servlet-name
>
TestServlet
</
servlet-name
>
<
description
>
Justfortest
</
description
>
<
servlet-class
>
servlets.TestServlet
</
servlet-class
>
<!--
因?yàn)镴SP頁(yè)面要轉(zhuǎn)換成sevlet,自然希望就像命名servlet一樣命名JSP頁(yè)面。為了命名JSP頁(yè)面,可將servlet-class元素替換為jsp-file元素
-->
</
servlet
>
<
servlet
>
<
servlet-name
>
HelloServlet
</
servlet-name
>
<
servlet-class
>
servlets.HelloServlet
</
servlet-class
>
<
init-param
>
<!--
該標(biāo)志定義外層servlet可以訪問(wèn)的變量的名稱、值和描述
-->
<
param-name
>
locale
</
param-name
>
<
param-value
>
US
</
param-value
>
</
init-param
>
<
load-on-startup
>
1
</
load-on-startup
>
<!--
在servlet的配置當(dāng)中,該標(biāo)記指示容器是否在啟動(dòng)的時(shí)候就加載這個(gè)servlet,當(dāng)值為0或者大于0時(shí),表示容器在應(yīng)用啟動(dòng)時(shí)就加載這個(gè)servlet當(dāng)是一個(gè)負(fù)數(shù)時(shí)或者沒(méi)有指定時(shí),則指示容器在該servlet被選擇時(shí)才加載,正數(shù)的值越小,啟動(dòng)該servlet的優(yōu)先級(jí)越高。
-->
<
security-role-ref
>
<!--
元素提供出現(xiàn)在服務(wù)器專用口令文件中的安全角色名的一個(gè)別名
-->
<!--
role-nameisusedinHttpServletRequest.isUserInRole(Stringrole)method.
-->
<
role-name
>
manager
</
role-name
>
<!--
role-linkisoneoftherole-namesspecifiedinsecurity-roleelements.
-->
<
role-link
>
supervisor
</
role-link
>
<
security-role-ref
>
</
servlet
>
<!--
Definesservletmappings
-->
<
servlet-mapping
>
<
servlet-name
>
TestServlet
</
servlet-name
>
<
url-pattern
>
/test/*
</
url-pattern
>
<!--
uil-pattern標(biāo)志確定上下文之后的標(biāo)志
-->
</
servlet-mapping
>
<
servlet-mapping
>
<
servlet-name
>
HelloServlet
</
servlet-name
>
<
url-pattern
>
*.hello
</
url-pattern
>
</
servlet-mapping
>
<
session-config
>
<!--
specifiessessiontimeoutas30minutes.
-->
<
session-timeout
>
30
</
session-timeout
>
</
session-config
>
<
mime-mapping
>
<
extension
>
jar
</
extension
>
<
mime-type
>
application/java-archive
</
mime-type
>
</
mime-mapping
>
<
mime-mapping
>
<!--
這個(gè)例子展示了自動(dòng)將application/pdfMIME類型與所有擴(kuò)展名為*.pdf的文件關(guān)聯(lián)起來(lái)
-->
<
extension
>
pdf
</
extension
>
<
mime-type
>
application/pdf
</
mime-type
>
</
mime-mapping
>
<
welcome-file-list
>
<
welcome-file
>
index.html
</
welcome-file
>
<
welcome-file
>
home.html
</
welcome-file
>
<
welcome-file
>
welcome.html
</
welcome-file
>
</
welcome-file-list
>
<
error-page
>
<
error-code
>
404
</
error-code
>
<
location
>
notfoundpage.jsp
</
location
>
</
error-page
>
<
error-page
>
<
exception-type
>
java.sql.SQLException
</
exception-type
>
<
location
>
sqlexception.jsp
</
location
>
</
error-page
>
<
taglib
>
<
taglib-uri
>
/examplelib
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/tlds/examplelib.tld
</
taglib-location
>
</
taglib
>
<
taglib
>
<
taglib-uri
>
http://abc.com/testlib
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/tlds/testlib.jar
</
taglib-location
>
<!--
可以是jar包
-->
</
taglib
>
<
taglib
id
="ABC_MATH_LIB"
>
<!--
可以有并只能有一個(gè)id作為屬性
-->
<
taglib-uri
>
/binomial
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/MathLib.tld
</
taglib-location
>
</
taglib
>
<
security-constraint
>
<
display-name
>
ExampleSecurityConstraint
</
display-name
>
<
web-resource-collection
>
<
web-resource-name
>
ProtectedArea
</
web-resource-name
>
<
url-pattern
>
/test/*
</
url-pattern
>
<!--
Whenthereisno<http-method>elementin<security-constraint>,allmethodsareprotected.
-->
<
http-method
>
POST
</
http-method
>
</
web-resource-collection
>
<
web-resource-collection
>
<
web-resource-name
>
AnotherProtectedArea
</
web-resource-name
>
<
url-pattern
>
*.hello
</
url-pattern
>
<!--
Allmethodsareprotectedasnohttp-methodisspecified
-->
</
web-resource-collection
>
<
auth-constraint
>
<!--
設(shè)定允許存取的角色名稱,必須符合<security-role>元素設(shè)定
-->
<
role-name
>
supervisor
</
role-name
>
</
auth-constraint
>
<!--
這個(gè)可選的元素指出在訪問(wèn)相關(guān)資源時(shí)使用任何傳輸層保護(hù)
-->
<
user-data-constraint
>
<!--
transport-guarantee為NONE值將對(duì)所用的通訊協(xié)議不加限制。INTEGRAL值表示數(shù)據(jù)必須以一種防止截取它的人閱讀它的方式傳送。雖然原理上INTEGRAL和CONFIDENTIAL之間可能會(huì)有差別,但在當(dāng)前實(shí)踐中,他們都只是簡(jiǎn)單地要求用SSL
-->
<
transport-guarantee
>
INTEGRAL
</
transport-guarantee
>
</
user-data-constraint
>
</
security-constraint
>
<
login-config
>
<!--
auth-methodcanbe:BASIC,FORM,DIGEST,orCLIENT-CERT
-->
<
auth-method
>
FORM
</
auth-method
>
<
realm-name
>
sales
</
realm-name
>
<!--
該標(biāo)志是驗(yàn)證用來(lái)確定某個(gè)特定的站點(diǎn)區(qū)域
-->
<
form-login-config
>
<
form-login-page
>
/formlogin.html
</
form-login-page
>
<
form-error-page
>
/formerror.jsp
</
form-error-page
>
</
form-login-config
>
</
login-config
>
<!--
Specifiestherolesthataredefinedintheapplicationserver.Forexample,Tomcatdefinesitinconf omcat-users.xml
-->
<
security-role
>
<
role-name
>
supervisor
</
role-name
>
</
security-role
>
<
security-role
>
<
role-name
>
worker
</
role-name
>
</
security-role
>
<!--
*****************************以下是J2EE元素的內(nèi)容*****************************
-->
<
resource-env-ref
>
<!--
聲明一個(gè)與某個(gè)資源有關(guān)的管理對(duì)象
-->
<
resource-env-ref-name
>
jms/StockQueue
</
resource-env-ref-name
>
<!--
一個(gè)相對(duì)于java:comp/env環(huán)境的JNDI名
-->
<
resource-env-ref-type
>
javax.jms.Queue
</
resource-env-ref-type
>
<!--
指定資源類型的完全限定的類
-->
</
resource-env-ref
>
<
env-entry
>
<!--
聲明Web應(yīng)用的環(huán)境項(xiàng)
-->
<
env-entry-name
>
minAmout
</
env-entry-name
>
<!--
一個(gè)相對(duì)于java:comp/env環(huán)境JNDI名
-->
<
env-entry-value
>
100.00
</
env-entry-value
>
<!--
項(xiàng)值
-->
<
env-entry-type
>
minAmout
</
env-entry-type
>
<!--
java.lang程序包中一個(gè)類型的完全限定類名,Boolean、String等
-->
</
env-entry
>
<!--
*****************************以下是JSP2.0新增加的內(nèi)容*****************************
-->
<!--
Servle
分享到:
比較完整的部署描述符(DTD)文件的例子
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
評(píng)論