当前位置: 代码迷 >> Web前端 >> Struts 1.x 在DispatchAction中获取web.xml中的配备参数
  详细解决方案

Struts 1.x 在DispatchAction中获取web.xml中的配备参数

热度:47   发布时间:2012-10-28 09:54:44.0
Struts 1.x 在DispatchAction中获取web.xml中的配置参数

知道Action类的源头是一个Servlet的控制器,那个从web.xml中获取配置参数是可行的。

?

试验了一下果然成功。代码如下:

?

web.xml中配置参数

?

<context-param>
	<param-name>pageSize</param-name>
	<param-value>3</param-value>	
</context-param>

?

DiapatchAction类中获取参数

?

try {
	this.pageSize = Integer.parseInt(servlet.getServletConfig().getServletContext().getInitParameter("pageSize"));		
	} catch(Exception e) {
			this.pageSize = 10;
		}

?

试验成功

  相关解决方案