Writing a bundle-based server application
While Equinox can be setup to run servlets and JSPs in a variety of ways, the technique for writing the applications is the same. Use the steps here to create your application and then one of the server setups detailed in the Server-side quick start guide to configure and run your server.
Writing the server application
The server application takes the form of static content, servlets and JSPs. You can use any combination of these.
- Create a new project - Next you need to create a bundle to contain the application. Your application can be made up
of many bundles but here we create just one. Create a new bundle project in the Eclipse IDE and call it
com.example.http.application
. - Add resources to your project - Add all of the static content files you need for your application by creating
a folder called
web_files
and putting your files there. - Place the resources - Now tell the server where your static
content lives within the bundle and where it should be placed in URL space. Create an extension by creating a plugin.xml
file with following content.
<plugin> <extension point="org.eclipse.equinox.http.registry.resources"> <resource alias="/files" base-name="/web_files"/> </extension> </plugin>
In the extension above, the
alias
attribute locates the resources in URL space and thebase-name
attribute describes where (in your bundle) the resources are located. So for example the file index.html would live inside thecom.example.http.application
bundle in theweb_files
folder and would be accessed using the URLhttp://localhost/files/index.html
. - Add some servlets - You can also add servlets by implementing classes that extent javax.serlvet.http.HttpServlet. Implement these in the example project as you would any class.
- Place the servlets - As with the resources, you need to tell the server where the servlets are and where they
should show up in URL space. Add the following XML to the plugin.xml file you created earlier. Ensure that this new element is placed within
the <plugin> element. Note that you can add any number of <resource> elements in the
one extension.
<extension point="org.eclipse.equinox.http.registry.servlets"> <servlet alias="/test" class="com.example.servlet.MyServlet"/> </extension>
In the extension above, the
alias
attribute locates the servlet in URL space and theclass
attribute identifies the class that implements the servlet. So for example the servlet MyServlet would be accessed using the URLhttp://localhost/test
. Note that you can add any number of <servlet> elements in the one extension.