我从 eclipse 中将我的 servlet 项目导出为一个 war 文件,并将它放在 webapp/hello 文件夹中。
/webapps/hello/hellotest.war
我如何运行它?
我输入了这个
http://127.0.0.1:8080/hello/foo
但是运行失败
这是我在 war 文件中的 web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>helloTest</display-name>
<servlet>
<description>
</description>
<display-name>foo</display-name>
<servlet-name>foo</servlet-name>
<servlet-class>
foo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>/foo</url-pattern>
</servlet-mapping>
<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>
</web-app>
最佳答案
将您的hellotest.war
文件放在Tomcat 的webapps
文件夹中。假设您的 Tomcat 实例正在运行并正确设置,它应该会自动将应用程序部署到文件夹 webapps/hellotest
。然后,您可以从 URL http://127.0.0.1:8080/hellotest/
访问您的应用程序。
关于java - war servlet tomcat找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5157736/