I would think that your first question is
simply a matter of scope. The ServletContext is a much more broad scoped
object (the whole servlet context) than a ServletRequest, which is
simply a single request. You might look to the Servlet specification
itself for more detailed information.
As to how, I am sorry but I will have to leave that for others to
answer at this time.
Context is stored at the application level
scope where as request is stored at page level i.e to say
Web Container brings up the applications one by one and run them
inside its JVM. It stores a singleton object in its jvm where it
registers anyobject that is put inside it.This singleton is shared
across all applications running inside it as it is stored inside the JVM
of the container itself.
However for requests, the container creates a request object that is
filled with data from request and is passed along from one thread to the
other (each thread is a new request that is coming to the server), also
request is passed to the threads of same application.
ServletContext的作用是什么:
ServletContext.getContect(java.lang.String uripath)的作用是什么?
返回同一Server中指定的path对应的ServletContext对象,通过该对象可以实现与Server中的其他Context打交道。
uripath必须是以"/"开始(该路径的含义是相对于整个Servlet文档的根路径,而不是当前ServletContext的根路径)。
ServletContext.getRequestDispatcher(String
url)和ServletRequest.getRequestDispatcher(String url)的区别是什么?为什么?
ServletContext.getRequestDispatcher(String
url)中的url只能使用绝对路径;而ServletRequest.getRequestDispatcher(String
url)中的url可以使用相对路径。
因为ServletRequest具有相对路径的概念;而ServletContext对象无次概念。
如何把请求转移到另外一个Web App中的某个地址?
ServletContext.getRequestDispatcher(String
url)和ServletRequest.getRequestDispatcher(String url)只能把请求转移到同一个Web
App中的地址。
如果需要把请求转移到另外一个Web App中的某个地址,可以按下面的做法:
1. 获得另外一个Web
App的ServletConext对象(currentServletContext.getContext(uripath)).
2. 调用ServletContext.getRequestDispatcher(String url)方法。
javax.servlet.FilterConfig翻译
========= START OF TOP NAVBAR ======= -->
<!-- -->
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
javax.servlet
Interface FilterConfig
public interface FilterConfig
A filter configuration object used by a servlet container to
pass information to a filter during initialization.
一个过滤器配置对象,在初始化过程中由servlet容器传递信息给过滤器。
Since:
Servlet 2.3
See Also:
Filter
<!-- ======== NESTED CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><!-- ========== METHOD SUMMARY =========== --><!-- -->
Method Summary
|
String
|
getFilterName
()
Returns the filter-name of this filter as
defined in the deployment descriptor. 返回过滤器在部署描述符中定义的名称。
|
String
|
getInitParameter
(
String
name)
Returns a String
containing the
value of the named initialization parameter, or null
if the
parameter does not exist. 返回命名的初始化参数的对应值,如果参数不存在返回null。
|
Enumeration
|
getInitParameterNames
()
Returns the names
of the filter's initialization parameters as an Enumeration
of String
objects, or an empty Enumeration
if
the filter has no initialization parameters.
返回以String对象的Enumeration形式的过滤器初始化参数名称,如果过滤器不含初始化参数,返回一个空Enumeration。
|
ServletContext
|
getServletContext
()
Returns a reference to the
ServletContext
in which the caller is executing. 返回调用者正在执行的ServletContext的引用。
|
<!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><!-- -->
<!-- -->
getFilterName
public
String
getFilterName
()
Returns the filter-name of this filter as defined in the
deployment descriptor. 返回过滤器在部署描述符中定义的名称。
<!-- -->
getServletContext
public
ServletContext
getServletContext
()
Returns a reference to the
ServletContext
in which the caller is executing. 返回调用者正在执行的ServletContext的引用。
Returns:
a
ServletContext
object, used by the caller to interact with its servlet container
由调用者和servlet容器交互的对象
See Also:
ServletContext
<!-- -->
getInitParameter
public
String
getInitParameter
(
String
name)
Returns a String
containing the value of the
named initialization parameter, or null
if the parameter
does not exist. 返回命名的初始化参数的对应值,如果参数不存在返回null。
Parameters:
name
- a String
specifying the name of the initialization
parameter 指定初始化参数名称的String
Returns:
a String
containing the
value of the initialization parameter 初始化参数的对应String值
<!-- -->
getInitParameterNames
public
Enumeration
getInitParameterNames
()
Returns the names of the filter's initialization parameters as
an Enumeration
of String
objects, or an empty
Enumeration
if the filter has no initialization
parameters.
返回以String对象的Enumeration形式的过滤器初始化参数名称,如果过滤器不含初始化参数,返回一个空Enumeration。
Returns:
an Enumeration
of String
objects containing the names of the filter's
initialization parameters 包含过滤器初始化参数的String对象的枚举
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<!-- -->
<!-- ======== END OF BOTTOM NAVBAR ======= -->
Submit a bug or feature
Copyright 2003 Sun Microsystems, Inc. All rights reserved.
相关推荐
本篇文章将深入探讨`ServletRequest`接口,以及如何使用它来处理来自客户端的请求。 ### ServletRequest接口 `ServletRequest`接口代表了客户端发送到服务器的一个请求,它是`javax.servlet`包下的核心接口。这个...
提供了ServletRequest过滤程序,重新构造对象内容,并有效规避request.getParameter()、request.getInputStream()冲突的问题,同时提供了对跨站脚本攻击XSS和SQL注入的过滤程序。
public void doFilter ServletRequest sRequest ServletResponse sResponse FilterChain chain throws IOException ServletException { HttpServletRequest request HttpServletRequest sRequest; String ...
本文将深入解析ServletRequest类的相关源代码,帮助你理解其内部工作机制。 首先,ServletRequest接口位于javax.servlet包下,它是所有请求对象(如HttpServletRequest)的基础。它定义了一系列方法,如...
`ServletRequest`接口是Java Servlet API中用于处理客户端请求的主要接口,它为开发者提供了获取请求数据的各种方法。`HttpServletRequest`是`ServletRequest`的一个实现类,专门针对HTTP协议,提供了更具体的操作...
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (encoding != null) { request.setCharacterEncoding(encoding); ...
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (encoding != null) { servletRequest.set...
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter("encoding"); String value = filterConfig....
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (encoding != null) { servletRequest.set...
The method setAttribute String Object in the type ServletRequest is not applicable for the arguments String int
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)...
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (encoding != null) { servletRequest.set...
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { System.out.println("filterDemo1 被执行了...."); ...
public void init(FilterConfig filterConfig) throws ServletException {} @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ...
超全面javaweb教程28天第9天_7_Servlet相关类之ServletRequest和Servletresponse对象
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter("encoding"); String value = filterConfig....
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)...
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getCharacterEncoding() == null) { String encoding = ...
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest...
ServletRequest request = (ServletRequest) servletRequest; try { request.setCharacterEncoding(targetEncoding); filterChain.doFilter(servletRequest, servletResponse); } catch (Exception ex) { ex....