---
title: "Struts 1.x 在DispatchAction中获取web.xml中的配置参数"
author: "enter775"
date: "2009-12-18T14:06:38Z"
tags: []
categories: ["企业架构"]
slug: "struts-1-x-dispatchaction-web-xml"
draft: false
lastmod: "2009-12-18T14:06:38Z"
id: 551325
url: "https://enter775.iteye.com/blog/551325"
---

知道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;
		}
```

 

试验成功