问题
I want to create a servlet to act as the container for a bunch of restlet applications. I have done servlet for one restlet application but I don't see how I can revise the web.xml to accommodate many applications. Here is web.xml for a single restlet: (taken almost verbatim from "Restlet in Action MEAP"):
<?xml version="1.0" encoding="UTF-8"?>
...
<display-name>Servlet engine as a container of Restlet applications</display-name>
<servlet>
<servlet-name>CompanyServerApplication</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>server.CompanyServerApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CompanyServerApplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
回答1:
Simply add additional <servlet>
and <servlet-mapping>
blocks to your web.xml
. For example, I've got separate Restlet applications for user requests and admin requests. My web.xml
looks like this:
<!-- user servlet -->
<servlet>
<servlet-name>user</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.myapp.server.resource.user.UserApplication</param-value>
</init-param>
<init-param>
<param-name>org.restlet.clients</param-name>
<param-value>HTTP HTTPS</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>user</servlet-name>
<url-pattern>/user/*</url-pattern>
</servlet-mapping>
<!-- admin servlet -->
<servlet>
<servlet-name>admin</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.myapp.server.resource.admin.AdminApplication</param-value>
</init-param>
<init-param>
<param-name>org.restlet.clients</param-name>
<param-value>HTTP HTTPS</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>admin</servlet-name>
<url-pattern>/admin/*</url-pattern>
</servlet-mapping>
来源:https://stackoverflow.com/questions/10691490/how-do-i-configure-the-web-xml-for-multiple-restlet-applications