我创建了一个Hello World servlet,并使用tomcat在本地服务器上运行它。它运行正常。
然后,我尝试将其映射到网址格式,页面显示错误The requested resource (/hello) is not available.
我的hello world servlet位于:
workspace\TestServletsApplication\src\com\msusevusal
我的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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>TestServletsApplication</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.msusevusal.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>TestServletsApplication</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.msusevusal.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
你的tomcat配置是什么? 如果您将应用程序放在%tomcat_home%/ webapps目录中,那么网址应该是 本地主机:8080 / APPNAME /你好