基本上我正在尝试将servlet映射到我的web.xml但它无法正常工作。
以下是我的表现:
项目目录:
C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\ROOT
仅供参考:我已经删除了所有apache默认的webapp文件并且已经推出了我自己的项目,所以可以使用localhost
来访问它,这样可以正常工作。
我的驱动器中的servlet位置:
C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\ROOT\src\duck\reg\pack\userlogin.java
我在eclipse IDE中的包: package in eclipse IDE Image
和我的web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>ROOT</display-name>
<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>userlogin</servlet-name>
<servlet-class>duck.reg.pack.userlogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>userlogin</servlet-name>
<url-pattern>/ROOT/WebContent/src</url-pattern>
</servlet-mapping>
</web-app>
我的HTML表单:
<form method="POST" action="/ROOT/WebContent/src" autocomplete="off">
.../ code
</form>
我不知道为什么但是这不起作用,而且我没有通过Ecplise运行apache
感谢所有回复:)
答案 0 :(得分:0)
按以下方式更改您的web.xml
<servlet-mapping>
<servlet-name>userlogin</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
并在您的HTML表单中
<form method="POST" action="userlogin.do" autocomplete="off">
.../ code
</form>
有关完整说明,请参阅本书Head First Servlets & JSP中的页面。