How do I configure the web.xml for multiple restlet applications?

為{幸葍}努か 提交于 2019-12-10 18:32:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!