大家好,
我对 J2EE 非常陌生。我必须将 servlet URL 访问为“localhost:8080”
我的 web.xml 文件如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Ticky taka</servlet-name>
<servlet-class>servlets.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ticky taka</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
问题是如果我想访问 Servlet,我必须提供 10.10.10.114:8080/TickyTacka/
URL。我希望将其设置为
10.10.10.114:8080
可以吗
我正在使用 Apache tomcat 7
请指教
谢谢
最佳答案
Tomcat 具有应用程序上下文路径的概念,在您的情况下,外部是应用程序的名称 TickyTacka
,以及内部 tomcap webapps
下安装应用程序的路径目录。
有一个特殊情况ROOT
应用程序上下文。在内部它是目录 webapps/ROOT
,但它被映射到一个空的应用程序上下文路径。因此,如果您将 Web 应用程序部署到 ROOT
可以通过 http://10.10.10.114:8080/
访问它.
但它是一种特殊的应用程序上下文,我知道不建议使用它。正如 vbera 所说,更常见的做法是在正常的应用程序上下文路径中部署应用程序,并通过 apache
隐藏 URL 重写后的这些路径。或nginx
.
关于java - url 仅映射 servlet 中的 ip_address 和端口 URL 中没有应用程序名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24823483/