gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 02:49:14 29 4
gpt4 key购买 nike

我想创建一个 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>

最佳答案

只需添加额外的 <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>

关于reSTLet - 如何为多个 reSTLet 应用程序配置 web.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10691490/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com