ServletContext:application 范围内的参数
此所设定的参
数, 在 JSP 网页中可以使用下列方法来取得:
- ${initParam.param0},
- <%=application.getInitParameter("param0") %><br/>
若在 Servlet 可以使用下列方法来获得:
- String param_name=getServletContext().getInitParameter("param0")
- =this.getServletConfig().getServletContext().getInitParameter("param0")
- =application.getInitParameter("param0");
使用上下文初始化参数:
- param_name
- avalible during application
- contextConfigLocation
- /web-INF/spring-configuration/*.xml
- <wiz_tmp_tag class="wiz-block-scroll">
部署在同一容器中的多个 Web 项目, 要配置不同的 webAppRootKey,web.xml 文件中最好定义 webAppRootKey 参数, 如果不定义, 将会缺省为 "webapp.root"
- webAppRootKey
- business.root
- webAppRootKey
- pubbase.root
在 web.xml 中该 Servlet 的定义标记中, 比如:
servlet 范围内的参数, 只能在 servlet 的 init() 方法中取得 (或者通过注解配置在对应的类上:@WebServlet("/MyServlet")
- System.out.println(this.getInitParameter("param1")=this.getServletConfig().getInitParameter(name));
- TimeServlet
- class>com.allanlxf.servlet.basic.TimeServletclass>
- param1
- avalible in servlet init()
- 0// 标记容器是否在启动的时候就加载这个 servlet, 执行 init() 方法, 初始化参数
配置监听器:(启动 Web 容器时, 自动装配 ApplicationContext,log4j 的配置信息.)
- contextConfigLocation
- /WEB-INF/spring-configuration/*.xml
- log4jConfigLocation
- WEB-INF/log4j.properties
- log4jRefreshInterval
- 6000
- org.springframework.web.util.Log4jConfigListener
- org.springframework.web.context.ContextLoaderListener
- com.yonyou.mcloud.cas.client.session.SingleSignOutHttpSessionListener
配置过滤器:
Filter 可认为是 Servle 的一种 "加强版", 主要用于对用户请求 request 进行预处理, 也可以对 Response 进行后处理, 是个典型的处理链. 使用 Filter 的完整流程是: Filter 对用户请求进行预处理, 接着将请求 HttpServletRequest 交给 Servlet 进行处理并生成响应, 最后 Filter 再对服务器响应 HttpServletResponse 进行后处理. Filter 与 Servlet 具有完全相同的生命周期, 且 Filter 也可以通过 < init-param > 来配置初始化参数, 获取 Filter 的初始化参数则使用 FilterConfig 的 getInitParameter().
换种说法, Servlet 里有 request 和 response 两个对象, Filter 能够在一个 request 到达 Servlet 之前预处理 request, 也可以在离开 Servlet 时处理 response,Filter 其实是一个 Servlet 链. 以下是 Filter 的一些常见应用场合, 创建一个过滤器, 实现 Filter 接口. 重新 init(), doFilter(), destroy().
注解的方式配置:@WebFilter(filterName="FirstFilter",urlPatterns={"/index.jsp"},initParams={WWebInitParam(name="mood",value="awake")})
urlPatterns: 哪些 URL 可以过滤, 默认 "/*"
initParams: 初始化哪些参数.
- CharacterEncodingFilter
- org.springframework.web.filter.CharacterEncodingFilter
- encoding
- UTF-8
- forceEncoding
- true
- CAS Single Sign Out Filter
- com.yonyou.mcloud.cas.client.session.SingleSignOutFilter
- CAS Authentication Filter
- com.yonyou.mcloud.cas.client.authentication.ExpandAuthenticationFilter
- casServerLoginUrl
- https://dev.yonyou.com:443/sso-server/login
- serverName
- http://10.1.215.40:80
- CAS Validation Filter
- org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter
- casServerUrlPrefix
- https://dev.yonyou.com:443/sso-server
- serverName
- http://10.1.215.40:80
- proxyCallbackUrl
- https://dev.yonyou.com:443/business/proxyCallback
- proxyReceptorUrl
- /proxyCallback
- proxyGrantingTicketStorageClass
- com.yonyou.mcloud.cas.client.proxy.MemcachedBackedProxyGrantingTicketStorageImpl
- encoding
- UTF-8
- CAS HttpServletRequest Wrapper Filter
- org.jasig.cas.client.util.HttpServletRequestWrapperFilter
- CAS Assertion Thread Local Filter
- org.jasig.cas.client.util.AssertionThreadLocalFilter
- NoCache Filter
- com.yonyou.mcloud.cas.client.authentication.NoCacheFilter
- CharacterEncodingFilter
- /*
- NoCache Filter
- /*
- CAS Single Sign Out Filter
- /*
- CAS Validation Filter
- /proxyCallback
- CAS Authentication Filter
- /*
- CAS Validation Filter
- /*
- CAS HttpServletRequest Wrapper Filter
- /*
- CAS Assertion Thread Local Filter
- /*
配置失效时间:
120
index.html
来源: https://www.cnblogs.com/shuchen007/p/9385034.html