Documentation for Confluence 2.5.4 - 2.5.8.
Documentation for [Confluence Cloud] and the latest Confluence Server is available too.

Servlet plugin modules enable you to deploy Java servlets as a part of your 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 servlet is an subclass of javax.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 again init() will be called again.
  • Because all servlet modules are deployed beneath a common /plugins/servlet root, be careful choosing each url-pattern under 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.

  • No labels