我试图在web.xml中映射多个servlet。在我的index.html中,我有一个表单,其中包含动作" DeskType.do",当我运行该程序时,它成功了。我从这开始:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>DeskType</servlet-name>
<servlet-class>controller.DeskType</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeskType</servlet-name>
<url-pattern>/DeskType.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
......工作得很好。它成功编译,按下我在index.html中设置的按钮,它按需运行。添加额外的servlet映射后:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>DeskType</servlet-name>
<servlet-class>controller.DeskType</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeskType</servlet-name>
<url-pattern>/DeskType.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Servers</servlet-name>
<url-pattern>/Servers.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
我收到了错误&#34;该模块尚未部署。 有关详细信息,请参阅服BUILD FAILED(总时间; 0秒)&#34;我不确定该怎么做,好像我把它拿出来就恢复正常工作了。有没有正确的方法来设置它?
答案 0 :(得分:0)
解决方案非常简单。您错过了新的<servlet-name>
和<servlet-class>
代码。这是修复。
<!-- YOU"RE MISSING BELOW LINES AND CHANGE THE PACKAGE NAME
WHERE Servers CLASS IS PRESENT -->
<servlet>
<servlet-name> <YOUR_SERVLET_NAME> </servlet-name>
<servlet-class> <SERVLET_PACKAGE_NAME> </servlet-class>
</servlet>
将前4行添加到web.xml
文件中。并分别用您的Servlet类名和它的包替换<YOUR_SERVLET_NAME>
和<SERVLET_PACKAGE_NAME>
。