Confluence 2.9 has reached end of life
Check out the [latest version] of the documentation
Servlet plugin modules enable you to deploy Java servlets as a part of your plugins.
- For more information about plugins in general, read Confluence Plugin Guide.
- To learn how to install and configure plugins (including macros), read Installing and Configuring Plugins Manually.
- For an introduction to writing your own plugins, read Writing Confluence Plugins
The Servlet Plugin Module
Each servlet is deployed as a plugin module of type "servlet". Here is an example atlassian-plugin.xml file containing a single servlet:
<atlassian-plugin name="Hello World Servlet" key="confluence.extra.helloworld">
<plugin-info>
<description>A basic Servlet module test - says "Hello World!"</description>
<vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
<version>1.0</version>
</plugin-info>
<servlet name="Hello World Servlet" key="helloWorld" class="com.atlassian.confluence.extra.helloworld.HelloWorldServlet">
<description>Says Hello World, Australia or your name.</description>
<url-pattern>/helloworld</url-pattern>
<init-param>
<param-name>defaultName</param-name>
<param-value>Australia</param-value>
</init-param>
</servlet>
</atlassian-plugin>
- the class attribute of
servletis an subclass ofjavax.servlet.http.HttpServlet. - the url-pattern elements (one or more) define the locations this servlet will be accessed.
- the init-param elements allow you to define initial parameters for your servlet, using the same method as you would normally in
web.xml.
Accessing Your Servlet
You servlet will be accessed within the Confluence web application via each url-pattern you specify, beneath the /plugins/servlet parent path.
For example, if you specify a url-pattern of /helloworld as above, and your Confluence application was deployed at http://yourserver/confluence - then you servlet would be accessed at http://yourserver/confluence/plugins/servlet/helloworld .
Notes
Some information to be aware of when developing or configuring a servlet plugin module:
- Your servlet's
init()method will not be called on web application startup, as for a normal servlet. Instead, this method will be called the first time your servlet is accessed after each time it is enabled. This means that if you disable a plugin containing a servlet, or a single servlet module, and re-enable it againinit()will be called again. - Because all servlet modules are deployed beneath a common
/plugins/servletroot, be careful choosing eachurl-patternunder which your servlet is deployed. It is recommended to use a value that will always be unique to the world!
Example
There is an example servlet module within the helloworldservlet example.
Find this example in the /plugins/helloworldservlet directory within your Confluence distribution.
