Struts2常量详解

-----------------siwuxie095

   

   

   

   

   

   

   

   

Struts2 常量详解

   

   

Struts2 的常量大多在默认的配置文件中已经配置好,但根据

用户需求开发要求的不同,可能需要修改这些常量值,修改

方法就是在配置文件中对其进行重新配置

   

   

   

Struts2 常量配置共有三种方式

   

· struts.xml 文件中使用 <constant> 标签配置常量(建议)

   

· struts.properties 文件中配置常量

   

· web.xml 文件中通过 <init-param> 标签配置常量

   

   

   

1、在 struts.xml 文件中使用 <constant> 标签配置常量

   

   

   

<struts>

   

<!-- 设置默认编码集为 UTF-8 -->

<constant name="struts.i18n.encoding" value="UTF-8"></constant>

<!-- 设置使用开发模式 -->

<constant name="struts.devMode" value="true"></constant>

   

</struts>

   

   

   

2、在 struts.properties 文件中配置常量(一般在 src 下创建)

   

   

   

### 设置默认编码集为 UTF-8

struts.i18n.encoding=UTF-8

   

### 设置不使用开发模式

struts.devMode=false

   

   

   

3、在 web.xml 文件中通过 <init-param> 标签配置常量

   

   

   

<filter>

<!-- 指定 Struts2 的核心过滤器 -->

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

<!-- 通过 init-param 标签配置 Struts2 常量,配置默认编码集为 UTF-8 -->

<!-- 注意:init-param 标签必须放在 filter 标签下 -->

<init-param>

<param-name>struts.i18n.encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

   

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

   

   

   

   

   

Struts2 默认常量配置文件 default.properties 的位置如下:

   

   

   

srccoresrcmain esourcesorgapachestruts2 文件夹下:

   

   

   

   

   

   

   

   

   

   

【made by siwuxie095】

原文地址:https://www.cnblogs.com/siwuxie095/p/7309782.html