如何为多个restlet应用程序配置web.xml?

时间:2012-05-21 19:37:52

标签: restlet

我想创建一个servlet来充当一堆restlet应用程序的容器。我已经为一个restlet应用程序完成了servlet,但是我没有看到如何修改web.xml以适应许多应用程序。以下是单个重定向的web.xml :(几乎逐字地从“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 个答案:

答案 0 :(得分:7)

只需向<servlet>添加其他<servlet-mapping>web.xml块即可。例如,我为用户请求和管理请求提供了单独的Restlet应用程序。我的web.xml看起来像这样:

<!-- 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>