Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
public interface ServletContext
Method Summary | |
Object |
|
Enumeration |
|
ServletContext |
|
String |
|
Enumeration |
|
int |
|
String |
|
int |
|
RequestDispatcher |
|
String |
|
RequestDispatcher |
|
URL |
|
InputStream |
|
String |
|
Servlet |
|
Enumeration |
|
Enumeration |
|
void |
|
void |
|
void |
|
void |
|
void |
|
public Object getAttribute(String name)
Gets the value of a named attribute
- Parameters:
name
- the name of the attribute
- Returns:
- the value of the attribute or null if there is no attribute with this name
- Since:
- Servlet API 1.0
public Enumeration getAttributeNames()
Gets an enumeration containing all the attribute names
- Returns:
- The enumeration containing all the attribute names
- Since:
- Servlet API 2.1
public ServletContext getContext(String UriPath)
Gives theServletContext
of another servlet indicated by theUriPath
on the same server. For security reasons this can return null even if there is an active servlet at that location. This can then be used to set attributes in the context of another servlet.
- Parameters:
UriPath
- The path to the servlet, such as/servlet/ShowBook
- Returns:
- ServletContext of the requested servlet or null if there is no servlet at the requested
UriPath
or when it is unavailable due to security restrictions
- Since:
- Servlet API 2.1
- See Also:
javax.servlet.ServletContext.setAttribute(java.lang.String, java.lang.Object)
public String getInitParameter(String name)
XXX
public Enumeration getInitParameterNames()
XXX
public int getMajorVersion()
Major version number of the Servlet API the servlet engine supports.
- Returns:
- 2 if the 2.1 Servlet API is supported
- Since:
- Servlet API 2.1
public String getMimeType(String filename)
Gives the mimetype of the requested file
- Parameters:
filename
- the file
- Returns:
- a String containing the mime type or null if the mime type cannot be determined
- Since:
- Servlet API 1.0
public int getMinorVersion()
Minor version number of the Servlet API the servlet engine supports.
- Returns:
- 1 if the 2.1 Servlet API is supported
- Since:
- Servlet API 2.1
public String getRealPath(String virtualPath)
Translates the requested virtual path to the real filesystem path using the servers knowledge of the document root. Use thegetResource
andgetResourceAsStream
methods to access the original object in a more abstract way not tied to the filesystem.
- Parameters:
virtualPath
- the path to be translated (e.g./graphics/baby-gnu.png
)
- Returns:
- the translated real filesystem path or null if the real system path cannot be found
- Since:
- Servlet API 1.0
- See Also:
javax.servlet.ServletContext.getResource(java.lang.String)
,javax.servlet.ServletContext.getResourceAsStream(java.lang.String)
public RequestDispatcher getRequestDispatcher(String UriPath)
Returns aRequestDispatcher
to forward requests or include responses from another (active) resource. Some resources can also be accessed by thegetResource
method.
- Parameters:
UriPath
- the path to another (active) resource (e.g./servlet/OtherServlet
)
- Returns:
- an
RequestDispatcher
for the (active) resource found atUriPath
- Since:
- Servlet API 2.1
- See Also:
javax.servlet.ServletContext.getResource(java.lang.String)
public URL getResource(String virtualPath) throws MalformedURLException
Translates the requested virtual path to an URL object that can be accesed by the servlet. This is more generic than thegetRealPath
method since it is not tied to the local filesystem. This means that a servlet can access the resource even when loaded in a servlet engine on a different machine. The servlet engine should make sure that the appropriateURLStreamHandlers
andURLConnection
classes are implemented to acces to resource. This can also be used to write to a resource if the resource (URLConnection
) supports it. The following example gives you anOutputStream
:
URLConnection con = getResource("/logs/mylog.txt").openConnection();
Note that a
con.setDoOutput(true);
OutputStream out = con.getOutputStream();
ServerContext
does not have to have access to the complete servers document space and is allowed to return null even for valid virtual paths. Note that according to the 2.1 API documentation this method can throw a MalformedURLException. But according to the official spec it does not throw any exceptions.
- Parameters:
virtualPath
- the path to the requested resource (e.g./philosophy/words-to-avoid.html
)
- Returns:
- the URL that can be used to access the resource or null if the resource cannot be found
- Since:
- Servlet API 2.1
- See Also:
java.net.URL.openConnection()
,java.net.URLConnection.setDoOutput(boolean)
,java.net.URLConnection.getOutputStream()
public InputStream getResourceAsStream(String virtualPath)
A convenience method forgetResource(virtualPath).openStream()
. But the servlet engine is allowed to implement is in a more efficient way.
- Parameters:
virtualPath
- the path to the requested resource (e.g./philosophy/words-to-avoid.html
)
- Returns:
- the InputStream that can be used to read the resource or null if the resource cannot be found
- Since:
- Servlet API 2.1
- See Also:
javax.servlet.ServletContext.getResource(java.lang.String)
,java.net.URL.openStream()
public String getServerInfo()
A server supplied string containing the server name, version number, etc
- Returns:
- the string
- Since:
- Servlet API 1.0
public Servlet getServlet(String name) throws ServletException
Deprecated. Always returns null. Since the servlet engine cannot know if a servlet ever gives up the reference to another servlet it could never destroy the servlet after this call. Only the servlet engine should have references to Servlets.
Gets a specific servlet by name. The Servlet is guaranteed to accept service requests.
- Parameters:
name
- the name of the wanted servlet
- Returns:
- null, used to return the servlet or null if not loaded.
- Throws:
ServletException
- if a servlet related error occured
- Since:
- Servlet API 1.0
public Enumeration getServletNames()
Deprecated. Always returns an empty Enumeration. Only the servlet engine should have references to Servlets.
Gets all servlet names
- Returns:
- Empty Enumeration, used to return an enumeration containing all loaded servlet names including the calling servlet name
- Since:
- Servlet API 2.0
public Enumeration getServlets()
Deprecated. Always returns an empty Enumeration. Only the servlet engine should have references to Servlets.
Gets all servlets
- Returns:
- Empty Enumeration, used to return an enumeration containing all loaded servlets including the calling servlet.
- Since:
- Servlet API 1.0
public void log(Exception exception, String message)
Deprecated. Use
log(String, Throwable)
which is more general.Writes an exception + message to the log
- Parameters:
exception
- the exceptionmessage
- the message
- Since:
- Servlet API 2.0
- See Also:
javax.servlet.ServletContext.log(java.lang.String, java.lang.Throwable)
public void log(String message)
Writes a message to the log
- Parameters:
message
- the message to write
- Since:
- Servlet API 1.0
public void log(String message, Throwable t)
Writes an exception + message to the log
- Parameters:
message
- the messaget
- the exception
- Since:
- Servlet API 2.1
public void removeAttribute(String name)
Removes the named object from theServletContext
- Parameters:
name
- The name which was used to set the object withsetObject
- Since:
- Servlet API 2.1
public void setAttribute(String name, Object o)
Puts a named object into theServletContext
. Can be used to communicate with other servlets in thisServletContext
. The names used must follow the conventions used for naming java packages.
- Parameters:
name
- - which is used to refer to this object
- Since:
- Servlet API 2.1
- See Also:
javax.servlet.ServletContext.getAttribute(java.lang.String)