Struts 1.x 在DispatchAction中获取web.xml中的配备参数
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; }
试验成功