如何删除结尾的“/”来自 Servlet 中的 URL 路径?
我想将 RPC 服务映射到 http://path.com/RPC2 而不是 /RPC2/
在我的 web.xml 文件中,我当前将 url-pattern 设置为 /< /strong>
<servlet-mapping>
<servlet-name>RPC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
我尝试仅删除 url-pattern,但这不起作用。当我删除 url-pattern 条目时,Tomcat 不会部署它,并且 Jetty 可以工作,但位于 ../RPC2/
以下是完整的 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<description>Automatos RPC Server</description>
<servlet-name>RPC2</servlet-name>
<servlet-class>RPCServlet</servlet-class>
<init-param>
<param-name>streamMessages</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<!-- Optional! Defaults to text/xml and ISO-8859-1 -->
<param-name>contentType</param-name>
<param-value>text/xml; charset=ISO-8859-1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RPC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
I want to map my RPC service to http://path.com/RPC2 rather than /RPC2/
Inside my web.xml file, I currently have the url-pattern set to /
<servlet-mapping>
<servlet-name>RPC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I tried to merely remove the url-pattern, but this didn't work. When I remove the url-pattern entry, Tomcat won't deploy it and Jetty works but at ../RPC2/
Here's the full XML file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<description>Automatos RPC Server</description>
<servlet-name>RPC2</servlet-name>
<servlet-class>RPCServlet</servlet-class>
<init-param>
<param-name>streamMessages</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<!-- Optional! Defaults to text/xml and ISO-8859-1 -->
<param-name>contentType</param-name>
<param-value>text/xml; charset=ISO-8859-1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RPC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在上下文根上部署您的 Web 应用程序(在 Tomcat 中,只需将 WAR 重命名为
ROOT.war
或设置
而不是<上下文路径=“/RPC2”>
)。这样您的 web 应用程序将部署到 http://path.com。这样,您就可以将 servlet 映射到/RPC2
URL 模式上,并且 servletcontainer 将不再自动重定向到 web 应用程序根/
。Deploy your webapp on context root (in Tomcat, just rename the WAR to
ROOT.war
or set<Context path="">
instead of<Context path="/RPC2">
). This way your webapp will be deployed to http://path.com. This way you can map the servlet on an URL pattern of/RPC2
and the servletcontainer won't auto-redirect to the webapp root/
anymore.