dwr的dwr.xml文件存放問題 持續更新

初步使用dwr,對很多裏面的東西不熟,在寫demo的過程中,將dwr.xml文件放在了resource文件下面,導致打包的時候文件被部署到classes文件下面,這樣dwr在默認情況下是讀取不到的,在網上查詢了一下,並看了一下dwr的加載源碼,發現dwr默認是在Web容器的WEB-INF下面自動加載dwr.xml文件的,那麼是否可以存放其他地方了,答案是當然的。下面是我在網上看到的一些詳細的講解,特此轉帖過啦。

轉自:http://www.blogjava.net/flyingis/archive/2006/11/18/81898.html


Multiple dwr.xml files and J2EE security

 

Generally speaking you will only need one dwr.xml file and that will be in the default position: WEB-INF/dwr.xml. So you can leave this paramter out.

There are 3 reasons why you might wish to specify a different position for dwr.xml:

 

一般情況下,你只需要一個 dwr.xml 文件,並且保存在默認的位置: WEB-INF/dwr.xml 。因此你可以不用做過多的考慮。但是,有三個原因讓你可能將 dwr.xml 放在其它的位置:

 

1. You wish to keep dwr.xml with the files that it gives access to. In which case the section might have a param-value something like <param-value>WEB-INF/classes/com/yourco/dwr/dwr.xml</param-value>.

 

1. 你希望將 dwr.xml 放在可以訪問的地方。這種情況下可能會有 param-value 標籤,如 <param-value>WEB-INF/classes/com/yourco/dwr/dwr.xml</param-value> 。

 

2. You may have a large number of remoted classes and wish to keep the definitions in separate files. In this case you will have the section above repeated several times each with a different param-name that begins 'config' and each pointing at a different file. DWR will read them all in turn.

 

2. 也許你需要大量的遠程類(的方法、屬性)在客戶端訪問,希望將它們分別定義在不同的文件中。這時,你需要將上面的代碼片斷複製在多處,並在 config 中使用不同的 param-name 指定每個文件。 DWR 將依次讀取。

 

3. DWR can use J2EE URL security built into the servlet spec to give different groups of users access to different functions. You simply define more than one dwr servlet by repeating the stanza at the top of the page with different names, urls and permissions.

 

3.DWR 能在指定的 servlet 中使用 J2EE URL 鏈接的安全機制,使不同的用戶組訪問不同的方法。你可以在文件的頂部使用不同的名稱、 url 鏈接和許可權限,簡單重複 dwr servlet 代碼來實現這種安全機制。

 

If you do wish to use it then the syntax is as follows:

 

如果你確實需要使用該安全機制,代碼構造如下:

 

<init-param>
<param-name>config*****</param-name>
<param-value>WEB-INF/dwr.xml</param-value>
<description>What config file do we use?</ description>
</init-param>

 

Where config***** means any param-name that begins with the string 'config'. This parameter can be specified as many times as required, however the param-name should be different for each.

 

config***** 代表命名以 'config' 開始的 param-name 。只要保證沒有重複的 param-name ,該參數可以根據需要被聲明多次。

 

An example configuration to use J2EE servlet security is as follows:

 

下面是基於 J2EE servlet 安全機制的配置示例:

 

<servlet >
<servlet-name>dwr-user-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</ servlet-class>
<init-param>
<param-name>config-user</param-name>
<param-value>WEB-INF/dwr-user.xml</ param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>dwr-admin-invoker</ servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</ servlet-class>
<init-param>
<param-name>config-admin</param-name>
<param-value>WEB-INF/dwr-admin.xml</ param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-admin-invoker</ servlet-name>
<url-pattern>/dwradmin/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dwr-user-invoker</servlet-name>
<url-pattern>/dwruser/*</url-pattern>
</servlet-mapping>
<security-constraint>
<display-name>dwr-admin </display-name >
<web-resource-collection>
<web-resource-name> dwr-admin-collection</ web-resource-name>
<url-pattern>/dwradmin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin </ role-name >
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>dwr-user </display-name >
<web-resource-collection>
<web-resource-name> dwr-user-collection</ web-resource-name>
<url-pattern>/dwruser/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user </ role-name >
</auth-constraint>
</security-constraint>

同時在寫demo的時候,我發現,把dwr.xml文件放到class目錄或者和spring資源文件一起放的其他路徑,而不是WEB-INF下時,不管是絕對路徑還是使用classpath:都不行,具體原因還不知道爲啥。

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