3

我想创建一个 servlet 来充当一堆 restlet 应用程序的容器。我已经为一个 restlet 应用程序完成了 servlet,但我不知道如何修改 web.xml 以适应许多应用程序。这是单个restlet的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>
4

1 回答 1

7

只需向您<servlet>的. 例如,我为用户请求和管理员请求提供了单独的 Restlet 应用程序。我的样子是这样的:<servlet-mapping>web.xmlweb.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>
于 2012-05-21T20:14:00.270 回答