Java Doc for ServletContext.java in  » EJB-Server-resin-3.1.5 » jsdk » javax » servlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server resin 3.1.5 » jsdk » javax.servlet 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.servlet.ServletContext

ServletContext
public interface ServletContext (Code)
ServletContexts encapsulate applications. Applications are generalized virtual hosts; a URL prefix defines a distinct application. So /myapp and /yourapp could define different applications. As a degenerate case, each virtual host has its own ServletContext.

Each application is entirely distinct. Each has its own:

  • Class loader -- each application gets its own beans and servlets.
  • ServletContext attributes
  • Servlets and servlet mappings (e.g. *.jsp could map to different servlets in different applications.)
  • File root
  • Mime mapping
  • Real-path mapping (aliases)

URIs are relative to the application root (e.g. /myapp) for most ServletContext methods. So you can define user workspaces with identical JSP files and servlets in different applications.

Including and forwarding

Forwarding and including files, the Servlet equivalent of SSI are handled by the RequestDispatcher methods.

Global initialization

There is no direct equivalent of a global.jsa. To initialize and cleanup shared classes on start and stop, use a load-on-startup servlet. The init() method will be called when the application starts and the destroy() method will be called when the application finishes.


 <servlet servlet-name='global'
 servlet-class='test.InitServlet'
 load-on-startup/>
 

Basic configuration

In the resin.conf, to define the /myapp application with a document root in /www/myweb, add the following to the resin.conf.

 <web-app id='/myapp' app-dir='/www/myweb'/>
 

Servlet and Bean locations (class loaders)

Each application has its own directories to load application servlets and beans. By default these are WEB-APP/classes and WEB-APP/lib. To add a servlet test.MyServlet, create the java file:
/www/myweb/WEB-APP/classes/test/MyServlet.java

Load balancing

When using load balancing with a web server, each JVM will have its own application object. The attributes are not shared. In contrast, sessions are always sent to the same JVM.

So the application object is best used as a cache rather than as a way for servlets to communicate.





Method Summary
public  ObjectgetAttribute(String name)
     Returns an attribute value.
Parameters:
  name - of the attribute.
public  EnumerationgetAttributeNames()
     Returns an enumeration of all the attribute names.
public  ServletContextgetContext(String uri)
     Returns the ServletContext for the uri.
public  StringgetContextPath()
     Returns the context-path for the web-application.
public  StringgetInitParameter(String name)
     Returns the value of an initialization parameter from the configuration file.
public  EnumerationgetInitParameterNames()
     Returns an enumeration of all init parameter names.
public  intgetMajorVersion()
     Returns the major version of the servlet API.
public  StringgetMimeType(String uri)
     Returns the mime type for the given uri.
public  intgetMinorVersion()
     Returns the minor version of the servlet API.
public  RequestDispatchergetNamedDispatcher(String servletName)
     Returns a request dispatcher based on a servlet name.
Parameters:
  servletName - the servlet name to include or forward to.
public  StringgetRealPath(String uri)
     Returns the real file path for the given uri.
public  RequestDispatchergetRequestDispatcher(String uri)
     Returns a request dispatcher for later inclusion or forwarding.
public  java.net.URLgetResource(String uri)
     Returns the resource for the given uri.
public  InputStreamgetResourceAsStream(String path)
     Returns the resource as a stream.
public  SetgetResourcePaths(String prefix)
     Returns the set all resources held by the application.
public  StringgetServerInfo()
     Returns a server-specific string identifying the servlet engine.
public  ServletgetServlet(String name)
    
public  StringgetServletContextName()
     Returns the URL prefix for the ServletContext.
public  EnumerationgetServletNames()
    
public  EnumerationgetServlets()
    
public  voidlog(String msg)
     Logs a message.
public  voidlog(String message, Throwable throwable)
     Logs a message and a stack trace.
public  voidlog(Exception exception, String msg)
    
public  voidremoveAttribute(String name)
     Removes an attribute.
public  voidsetAttribute(String name, Object value)
     Sets an attribute value.



Method Detail
getAttribute
public Object getAttribute(String name)(Code)
Returns an attribute value.
Parameters:
  name - of the attribute. stored value



getAttributeNames
public Enumeration getAttributeNames()(Code)
Returns an enumeration of all the attribute names.



getContext
public ServletContext getContext(String uri)(Code)
Returns the ServletContext for the uri. Note: the uri is not relative to the application.
Parameters:
  uri - path relative to the root the ServletContext responsible for the given uri.



getContextPath
public String getContextPath()(Code)
Returns the context-path for the web-application.



getInitParameter
public String getInitParameter(String name)(Code)
Returns the value of an initialization parameter from the configuration file. The Resin configuration looks something like:

 <web-app id='/myapp' app-dir='/www/myapp'>
 <context-param name1='value1'/>
 <context-param name2='value2'/>
 </web-app>
 

Parameters:
  name - init parameter name init parameter value



getInitParameterNames
public Enumeration getInitParameterNames()(Code)
Returns an enumeration of all init parameter names.



getMajorVersion
public int getMajorVersion()(Code)
Returns the major version of the servlet API.



getMimeType
public String getMimeType(String uri)(Code)
Returns the mime type for the given uri.
Parameters:
  uri - path relative to the application root.



getMinorVersion
public int getMinorVersion()(Code)
Returns the minor version of the servlet API.



getNamedDispatcher
public RequestDispatcher getNamedDispatcher(String servletName)(Code)
Returns a request dispatcher based on a servlet name.
Parameters:
  servletName - the servlet name to include or forward to. RequestDispatcher for later inclusion or forwarding.



getRealPath
public String getRealPath(String uri)(Code)
Returns the real file path for the given uri. The file path will be in native path format (with native path separators.)

See ServletRequest to return the real path relative to the request uri.
Parameters:
  uri - path relative to the application root to be translated. native file path for the uri.




getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String uri)(Code)
Returns a request dispatcher for later inclusion or forwarding. This is the servlet API equivalent to SSI includes. The uri is relative to the application root.

The following example includes the result of executing inc.jsp into the output stream. If the context path is /myapp, the equivalent uri is /myapp/inc.jsp

 RequestDispatcher disp;
 disp = getRequestDispatcher("/inc.jsp?a=b");
 disp.include(request, response);
 

See ServletRequest to return a request dispatcher relative to the request uri.
Parameters:
  uri - path relative to the app root (including query string)for the included file. RequestDispatcher for later inclusion or forwarding.




getResource
public java.net.URL getResource(String uri) throws java.net.MalformedURLException(Code)
Returns the resource for the given uri. In general, the RequestDispatcher routines are more useful.
Parameters:
  uri - path relative to the application root.



getResourceAsStream
public InputStream getResourceAsStream(String path)(Code)
Returns the resource as a stream. In general, the RequestDispatcher routines are more useful.
Parameters:
  uri - path relative to the application root. InputStream to the resource.



getResourcePaths
public Set getResourcePaths(String prefix)(Code)
Returns the set all resources held by the application.



getServerInfo
public String getServerInfo()(Code)
Returns a server-specific string identifying the servlet engine.



getServlet
public Servlet getServlet(String name) throws ServletException(Code)



getServletContextName
public String getServletContextName()(Code)
Returns the URL prefix for the ServletContext.



getServletNames
public Enumeration getServletNames()(Code)



getServlets
public Enumeration getServlets()(Code)



log
public void log(String msg)(Code)
Logs a message.



log
public void log(String message, Throwable throwable)(Code)
Logs a message and a stack trace.



log
public void log(Exception exception, String msg)(Code)



removeAttribute
public void removeAttribute(String name)(Code)
Removes an attribute. Because servlets are multithreaded, removing ServletContext attributes will generally need synchronization.
Parameters:
  name - of the attribute.



setAttribute
public void setAttribute(String name, Object value)(Code)
Sets an attribute value. Because servlets are multithreaded, setting ServletContext attributes will generally need synchronization.

A typical initialization of an application attribute will look like:

 ServletContext app = getServletContext();
 Object value;
 synchronized (app) {
 value = app.getAttribute("cache");
 if (value == null) {
 value = new Cache();
 app.setAttribute("cache", value);
 }
 }
 

Parameters:
  name - of the attribute.
Parameters:
  value - value to store



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.