【发布时间】:2017-03-20 04:43:40
【问题描述】:
我向我的 Web 应用程序和一个 servlet 映射添加了一个 servlet,但是当我转到我的网页时,现在除了一个空白屏幕之外什么都没有,并且在开发人员控制台中没有错误。有人可以帮忙吗?
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>BasicJavaWeb</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>
<display-name>AuthenticatorServlet</display-name>
<servlet-name>AuthenticatorServlet</servlet-name>
<servlet-class>AuthenticatorServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthenticatorServlet</servlet-name>
<url-pattern>authenticator</url-pattern>
<url-pattern>authenticator</url-pattern>
</servlet-mapping>
</web-app>
在我添加 servlet/servlet-mappings 之前,这个 web.xml 文件确实显示了 index.html:
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>BasicJavaWeb</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>
</web-app>
那么仅添加 servlet 会出现什么问题?
【问题讨论】:
-
检查您的控制台。你可能有一个错误。并且该错误可能是由于您的 servlet 类位于默认包中。永远永远不会将任何类放在默认包中。
-
谢谢!我确实检查了控制台并没有看到任何错误 - 但我使用的是默认包并将其移至新包。但它仍然无法正常工作。