struts2框架常量配置的三种方式

struts2框架常量配置的三种方式

1.在struts.xml中使用标签:

这些常量可见struts2-core-x.x.x.jar核心包下的org.apache.struts2中的default.properties文件

    <!-- 
		constant:配置常量
		
		i18n:国际化 解决post提交乱码
	 -->
	<constant name="struts.i18n.encoding" value="UTF-8"></constant>
	
	<!-- 指定访问action是的后缀名
		http://localhost:8080/struts2_day01/hello/HelloAction.do	
	 -->
	<constant name="struts.action.extension" value="do"></constant>
	
	<!-- 指定struts2是否以开发者模式运行
		1.热加载主配置(不需要重启即可生效)
		2.提供更多错误的信息输出,方便开发时的调试
		
		但是在项目上线时需要关闭(因为消耗资源)
	 -->
	<constant name="struts.devMode" value="true"></constant>

2.在src下创建struts.properties文件在里面写键值对  如: struts.i18n.encoding=UTF-8

3.web.xml中配置

<context-param>
 	<param-name>struts.i18n.encoding</param-name>
 	<param-value>UTF-8</param-value>
</context-param>

以上的1,2,3也是加载的顺序 也就是说如果在3会覆盖前面相同的常量 最终使用的是web.xml中的常量配置

猜你喜欢

转载自blog.csdn.net/weixin_40471291/article/details/82221708