---
title: "SSH集成后如何在Action中获取web.xml中<context-param>的参数值"
author: "orange5458"
date: "2008-12-18T11:47:44Z"
tags: []
slug: "ssh-action-web-xml-context-param"
draft: false
lastmod: "2008-12-18T11:47:44Z"
id: 296421
url: "https://orange5458.iteye.com/blog/296421"
---

我想在Action的分页实现方法中获取web.xml中&lt;context-param&gt;配置的pageSize(页面的最大数据条数)，

但是运行后发现在Action中连ActionServlet都获取不了。

 

希望有人能帮我解决此问题，谢谢。。。。。

 

下面是分页流程的主要类和配置

 

web.xml：

 

 &lt;context-param&gt;  
  &lt;param-name&gt;pageSize&lt;/param-name&gt;  
  &lt;param-value&gt;5&lt;/param-value&gt;  
 &lt;/context-param&gt;

 

 

ProductManagerAction：

 

public class ProductManagerAction extends MappingDispatchAction {  
 private Logger logger = Logger.getLogger(ProductManagerAction.class);  
 private ProductService productService;

 public void setProductService(ProductService productService) {  
  this.productService = productService;  
 }

 public ActionForward listCategory(ActionMapping mapping, ActionForm form,  
   HttpServletRequest request, HttpServletResponse response)  
   throws Exception {  
  int currentPage = 1;  
  System.out.println("--------------------------------------");  
  System.out.println(this.getServlet());  
  System.out.println(this.getServlet().getServletContext());  
  System.out.println(this.getServlet().getServletContext().getInitParameterNames());  
  int pageSize = Integer.parseInt(this.getServlet().getServletContext().getInitParameter("pageSize"));  
  Pager pager = new Pager(currentPage, pageSize, productService.getCategoryAmount());  
  String currPage = request.getParameter("currentPage");  
  if((currPage != null)){  
   try {  
    currentPage = Integer.parseInt(currPage);  
    if(currentPage&lt;1 || currentPage&gt;pager.getTotalPage())  
     currentPage = 1;  
   } catch (NumberFormatException e) {  
    logger.fatal("----------管理员改变URL中currentPage的值,使之不可转化为int类型数据--------------");  
   }  
  }  
  pager.setCurrentPage(currentPage);  
  request.setAttribute("pager", pager);  
  List&lt;Category&gt; categories = productService.listCategories(currentPage, pageSize);  
  request.setAttribute("categories", categories);  
  return mapping.findForward("success");  
 }

}

 

 

struts-config.xml:

 

&lt;action path="/manager/product/categoryManager"  
    type="org.springframework.web.struts.DelegatingActionProxy"  
    parameter="listCategory"&gt;  
   &lt;forward name="success" path="/manager/product/listCategory.jsp"&gt;&lt;/forward&gt;  
  &lt;/action&gt;

applicationContext-web.xml:

 

&lt;bean id="productManager" class="com.siyuan.estore.struts.action.ProductManagerAction" abstract="true"&gt;  
  &lt;property name="productService" ref="productService"&gt;&lt;/property&gt;  
 &lt;/bean&gt;  
 &lt;bean name="/manager/product/categoryManager" parent="productManager"&gt;&lt;/bean&gt;

 

运行时console输出：

 --------------------------------------  
null