Struts2配置詳解!
Struts2框架按照以下搜索順序加載Struts2常量:
1.struts-default.xml---該文件保存在struts2-core-2.x.x.jar文件中
2.struts-pluugin.xml---在struts2一些插件jar包里,比如struts2-xxx-plugin-2.3.x.x.jar
3.struts.xml---Web應用默認的Struts2配置文件
4.struts.properties---Web應用默認的Struts2配置文件
5.web.xml--Web應用的配置文件
如果多個文件中配置同一個常量,則后者覆蓋前者,常量的配置為兩個屬性,常量name和常量value
一、常量配置
Struts2中配置常量通常都是在struts.xml中配置,因為方便管理還有統一,當然也可以在struts.properties文件來配置,專門用作于struts2的常量配置文件,還有一種是在web.xml里配置
1.struts.xml-----通常推薦配置在這里
< struts > |
</tr>
</tbody>
</table>
</div>
< constant name = "struts.i18n.encoding" value = "UTF-8" /> |
</tr>
</tbody>
</table>
</div>
...... |
</tr>
</tbody>
</table>
</div>
</ struts > |
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
2.struts.properties--<K-V>形式,K-name V-value
### 設置Web應用的字符編碼 |
</tr>
</tbody>
</table>
</div>
struts.i18n.encoding=UTF-8 |
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
3.web.xml-----未試驗過
< filter > |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< filter-name >struts2</ filter-name > |
</tr>
</tbody>
</table>
</div>
< filter-class >org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</ filter-class > |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< init-param > |
</tr>
</tbody>
</table>
</div>
< param-name >struts.i18n.encoding</ param-name > |
</tr>
</tbody>
</table>
</div>
< param-value >UTF-8</ param-value > |
</tr>
</tbody>
</table>
</div>
</ init-param > |
</tr>
</tbody>
</table>
</div>
</ filter > |
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
二、常量詳解
< struts > |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.i18n.encoding" value = "UTF-8" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.action.extension" value = "do" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.serve.static.browserCache" value = "false" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.configuration.xml.reload" value = "true" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.devMode" value = "true" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.ui.theme" value = "simple" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.objectFactory" value = "spring" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.configuration" |
</tr>
</tbody>
</table>
</div>
value = "org.apache.struts2.config.DefaultConfiguration" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.locale" value = "zh_CN" /> |
</tr>
</tbody>
</table>
</div>
< constant name = "struts.i18n.encoding" value = "GBK" /> |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
< constant name = "struts.objectFactory" value = "spring" ></ constant > |
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>
|
</tr>
</tbody>
</table>
</div>