以下是本人项目中用到的配置参数等。
web.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>ROOT</display-name> <context-param> <!--application范围内的参数,存放在servletcontext中 --> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml,classpath:applicationContext-*.xml </param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/hibernate-context.xml</param-value> </context-param> <context-param> <param-name>directoryListing</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <!-- 过滤器,为了过滤字符编码--> <filter> <filter-name>EncodingFilter</filter-name> <filter-class> com.futuresoftware.ccmbam.util.EncodingFilter </filter-class> <!--传入指定的参数,init-param指的是初始化参数,在类中可以调用 --> <!--public class EncodingFilter implements Filter { private static String encoding="UTF-8"; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(EncodingFilter.encoding); response.setCharacterEncoding(EncodingFilter.encoding); chain.doFilter(request,response); } public void init(FilterConfig config) throws ServletException { String charset=config.getInitParameter("encoding"); if(null!=charset && !"".equals(charset.trim())){ EncodingFilter.encoding=charset; } } --> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter> <!-- 关于OpenSessionInViewFilter 的介绍在 http://woshixushigang.iteye.com/blog/1144585 中有介绍--> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> </filter> <filter> <filter-name>LoginFilter</filter-name> <filter-class> com.futuresoftware.leadinfo.sso.filter.LoginFilter </filter-class> </filter> <filter-mapping> <!--访问项目的各个网页都会走过滤字节的类 --> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <!--对地址为.do 的请求过滤并且走设置的过滤方法 --> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <!--只对/0/目录下的文件进行登录过滤 --> <filter-name>LoginFilter</filter-name> <url-pattern>/0/*</url-pattern> </filter-mapping> <listener> <!--监听器配置,监听key登录时候的请求 --> <listener-class> com.futuresoftware.leadinfo.sso.login.SSOsession </listener-class> </listener> <servlet> <servlet-name>PropertiesListener</servlet-name> <servlet-class> com.futuresoftware.ccmbam.synchronization.PropertiesListener </servlet-class> <!--启动容器的时候经过多久启动 servlet --> <load-on-startup>6</load-on-startup> </servlet> <servlet> <servlet-name>SpringContextServlet</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class><!--第一种参数在servlet里面可以通过getServletContext().getInitParameter("context/param")得到 第二种参数只能在servlet的init()方法中通过this.getInitParameter("param1")取得
init-param属于一个servlet所有,context-param属于整个应用程序所有 ,不仅是在servlet中可以得到,jsp文件中也可以得到.
在jsp中config就相当于这里的servletContext,<%=config.getServletContext().getInitParameter("...") %>. action中ServletActionContext.getServletContext().getInitParameter("...").
--> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet> <servlet-name>InitPropertiesServlet</servlet-name> <servlet-class> com.futuresoftware.ccmbam.setting.InitPropertiesServlet </servlet-class> <!--servlet的初始化参数 --> <init-param> <param-name> com.futuresoftware.ccmcms.properties </param-name> <!--传入的初始化参数值 --> <param-value>/WEB-INF/ccmcms.properties</param-value> </init-param> <!--启动顺序 --> <load-on-startup>4</load-on-startup> </servlet> <servlet> <!--模板引擎配置的servlet --> <servlet-name>velocity</servlet-name> <servlet-class> org.apache.velocity.tools.view.servlet.VelocityViewServlet </servlet-class> <init-param> <!--给模板引擎servlet传入的参数值 --> <param-name>org.apache.velocity.toolbox</param-name> <param-value>/WEB-INF/toolbox.xml</param-value> </init-param> <init-param> <param-name>org.apache.velocity.properties</param-name> <param-value>/WEB-INF/ccmcms.properties</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> <servlet> <!--ajax框架 dwr配置 --> <servlet-name>dwr-invoker</servlet-name> <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <load-on-startup>5</load-on-startup> </servlet> <servlet> <servlet-name>toHtml</servlet-name> <servlet-class> com.futuresoftware.portal.servlet.JspTransToHtmlServlet </servlet-class> </servlet> <servlet> <servlet-name>ForwardApp</servlet-name> <servlet-class> com.futuresoftware.leadinfo.sso.login.ForwardApp </servlet-class> </servlet> <!-- FCKEditor start --> <servlet> <servlet-name>Connector</servlet-name> <servlet-class> net.fckeditor.connector.ConnectorServlet </servlet-class> <init-param> <param-name>baseDir</param-name> <param-value>/uploadfile/</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- FCKEditor end --> <!-- RTX servlet begin --> <servlet> <servlet-name>RTX</servlet-name> <servlet-class>rtx.RTX</servlet-class> </servlet> <servlet-mapping> <servlet-name>RTX</servlet-name> <url-pattern>/RTX</url-pattern> </servlet-mapping> <!-- RTX servlet end --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>toHtml</servlet-name> <url-pattern>/toHtml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>velocity</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>InitPropertiesServlet</servlet-name> <url-pattern>/initProperties</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>ForwardApp</servlet-name> <url-pattern>/ForwardApp.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Connector</servlet-name> <url-pattern> /fckeditor/editor/filemanager/connectors/* </url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/sso/dl.jsp</welcome-file> </welcome-file-list> <error-page> <error-code>500</error-code> <location>/locationError.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/locationError1.jsp</location> </error-page> <!-- Struts Tag Library Descriptors --> <taglib> <!--标签库描述符 --> <taglib-uri>/taglib/struts-bean</taglib-uri> <taglib-location> /WEB-INF/taglib/struts-bean.tld </taglib-location> </taglib> <taglib> <taglib-uri>/taglib/struts-html</taglib-uri> <taglib-location> /WEB-INF/taglib/struts-html.tld </taglib-location> </taglib> <taglib> <taglib-uri>/taglib/struts-logic</taglib-uri> <taglib-location> /WEB-INF/taglib/struts-logic.tld </taglib-location> </taglib> <taglib> <taglib-uri>/taglib/struts-nested</taglib-uri> <taglib-location> /WEB-INF/taglib/struts-nested.tld </taglib-location> </taglib> <taglib> <taglib-uri>/taglib/struts-template</taglib-uri> <taglib-location> /WEB-INF/taglib/struts-template.tld </taglib-location> </taglib> <taglib> <taglib-uri>/taglib/struts-tiles</taglib-uri> <taglib-location> /WEB-INF/taglib/struts-tiles.tld </taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/core</taglib-uri> <taglib-location>/WEB-INF/c-1_0.tld</taglib-location> </taglib> </web-app>